I am currently working on a usecase where I have implemented APIs in python and they need to return struct, vector and map to C++ caller functions. Could you please help me with an example how to do that. All the usecases I see in pybind/boost python is just simply python being embedded in C++ without any return value. I came across your blog as well that explained the two libraries pretty well. But I could not proceed because of this usecase. The scenario which I need to implement is a python -> C++ interface where the C++ caller will start a session and call various python objects when it wants and then close the session. I am ok with solution both in boost::python or pybind11
Asked
Active
Viewed 1,010 times
0
-
This is not a [MCVE]; please provide one, boiling down your code to the *minimal* amount needed for *someone else* to reproduce the problem. – ShadowRanger Aug 16 '18 at 00:56
1 Answers
0
"All the usecases I see in pybind/boost python is just simply python being embedded in C++ without any return value."
PyBind11 Example with return value
The example the called python function returns an int which they assign first to a py::object and then cast to an int. For STL containers like std::map, std::vector there is automatic conversion if you #include <pybind11/stl.h>
. I am unsure about conversion to struct, but I would use one of PyBind's built in STL conversions between Python and C++ and then construct the struct on the C++ side.

dwagnerkc
- 488
- 4
- 8