Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 314
Kris Avatar asked May 11 '13 14:05

Kris


1 Answers

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);
like image 101
Kris Avatar answered Sep 21 '22 16:09

Kris