Search code examples
c++pythonbooststdboost-python

How to expose std::pair to python using boost::python?


How to expose std::pair to python using boost::python? When I expose for example vector<string> I simply write:

class_<std::vector<std::string> >("StringVec")
    .def(vector_indexing_suite<std::vector<std::string> >())
;

But I don't know how to deal with std::pair.


Solution

  • I found a solution. The most simple example of exposing std::pair is:

    class_<std::pair<int, int> >("IntPair")
        .def_readwrite("first", &std::pair<int, int>::first)
        .def_readwrite("second", &std::pair<int, int>::second);