1 [section boost/python/return_by_value.hpp]
2 [section Class `return_by_value`]
3 `return_by_value` is a model of [link concepts.resultconverter.resultconvertergenerator_concept ResultConverterGenerator] which can be used to wrap C++ functions returning any reference or value type such that the return value is copied into a new Python object.
5 namespace boost { namespace python
9 template <class T> struct apply;
14 [section Class `return_by_value` metafunctions]
15 ``template <class T> struct apply``
17 [[Returns][`typedef to_python_value<T> type;`]]
23 #include <boost/python/module.hpp>
24 #include <boost/python/class.hpp>
25 #include <boost/python/return_by_value.hpp>
26 #include <boost/python/return_value_policy.hpp>
39 using namespace boost::python;
41 void def_void_function(char const* name, R (*f)())
43 def(name, f, return_value_policy<return_by_value>());
46 BOOST_PYTHON_MODULE(my_module)
49 def_void_function("b1", b1);
50 def_void_function("b2", b2);
51 def_void_function("b3", b3);
56 >>> from my_module import *
57 >>> b = b1() # each of these calls
58 >>> b = b2() # creates a brand
59 >>> b = b3() # new Bar object