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
"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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.