I want to get the same python instance back for subsequent calls to the C++ function e.g. I want this to work for the C++ structure below:
import ident_ext o = ident_ext.Owner() assert o.get() is o.get() How can I get this behaviour in boost::python? It looked like call policies was the right sort of place to look, but can't get that to behave how I want. I can get this to work in pybind11 but not boost (and unfortunately our project is heavily dependent on boost::python). My working c++ is: #include <boost/python.hpp> #include <iostream> using namespace boost::python; class Something { public: void name(void) { std::cout << this << std::endl; } }; class Owner { Something *_shared = nullptr; public: Something &get() { if (_shared == nullptr) { _shared = new Something(); } return *_shared; } }; BOOST_PYTHON_MODULE(ident_ext) { class_<Something>("Something").def("name", &Something::name); class_<Owner>("Owner").def("get", &Owner::get, return_internal_reference<>()); } _______________________________________________ Cplusplus-sig mailing list Cplusplus-sig@python.org https://mail.python.org/mailman/listinfo/cplusplus-sig