1 [section boost/python/manage_new_object.hpp]
2 [section Class `manage_new_object`]
3 `manage_new_object` is a model of [link concepts.resultconverter.resultconvertergenerator_concept ResultConverterGenerator] which can be used to wrap C++ functions which return a pointer to an object allocated with a new-expression, and expect the caller to take responsibility for deleting that object.
5 namespace boost { namespace python
7 struct manage_new_object
9 template <class T> struct apply;
14 [section Class `manage_new_object` metafunctions]
15 ``template <class T> struct apply``
17 [[Requires][`T` is `U*` for some `U`.]]
18 [[Returns][`typedef to_python_indirect<T> type;`]]
24 #include <boost/python/module.hpp>
25 #include <boost/python/class.hpp>
26 #include <boost/python/manage_new_object.hpp>
27 #include <boost/python/return_value_policy.hpp>
32 int get_x() { return x; }
36 Foo* make_foo(int x) { return new Foo(x); }
39 using namespace boost::python;
40 BOOST_PYTHON_MODULE(my_module)
42 def("make_foo", make_foo, return_value_policy<manage_new_object>())
44 .def("get_x", &Foo::get_x)
50 >>> from my_module import *
51 >>> f = make_foo(3) # create a Foo object