I have the following C++ code:
struct MyType { int x, y; };
struct A {
std::vector<MyType> get_data();
};
which I want to interface to Python using Boost Python so that it can be used in the following way:
a = A()
ret = a.get_data();
for r in ret:
print('x=%d; y=%d;' % (r['x'], r['y']))
What I have now is a rather naive:
BOOST_PYTHON_MODULE(pyA) {
class_<A>("A").def("get_data", &A::get_data);
}
which gives me, as expected, the following error
TypeError: No to_python (by-value) converter found for C++ type
when I try to call the get_data() function from the Python code.
I have seen posts on here (such as std::vector to boost::python::list) which describe how to use vector_indexing_suite to convert a std::vector<T> to a list for some types T (e.g. floats, strings), but I'm not sure how to extend this to deal with my struct -> dict conversion as well. Any help would be greatly appreciated.