I have a C ++ class that provides collections by providing functions that return ranges using boost::range .
To export this class in python using boost::python , I use the boost::python::range function, which can take two parameters: class member functions that return the beginning and end of collection iterators.
I want to avoid manually writing start / end pairs for each collection, as I already provide a range. But I canβt write a wrapper over boost :: python :: range, which takes a member function that returns a range as an argument. Any ideas? (I actually have more than one class that is templatized, so the template function taking the address of the member function of the template class as a template parameter will not work, my compiler said)
I will accept a C ++ 0x solution if it is compiled with g ++ - 4.6.
edit: code example: let's say I have this class:
struct A { std::vector<int> c; typedef boost::sub_range<std::vector<int> > c_range; c_range getc() { return c; } };
To create a Python iterator from the getc method, I now add these two member functions to class A:
c_range::iterator c_begin() { return getc().begin(); } c_range::iterator c_end() { return getc().end(); }
and then set them as follows:
boost::python::class_<A>("A") .def("getc", boost::python::range(&A::c_begin, &A::c_end));
Is there a way to write directly something like:
.def("getc", pyrange(&A::getc));
and avoid the need to write c_begin and c_end ?