1 [section boost/python/return_arg.hpp]
3 `return_arg` and `return_self` instantiations are models of [link concepts.callpolicies `CallPolicies`] which return the specified argument parameter (usually `*this`) of a wrapped (member) function.
5 [section Class `return_arg`]
7 [[Parameter][Requirements][Description][Default]]
8 [[arg_pos][A positive compile-time constant of type `std::size_t`.][the position of the argument to be returned.][1]]
9 [[Base][A model of [link concepts.callpolicies `CallPolicies`]][Used for policy composition. Any `result_converter` it supplies will be overridden by `return_arg`, but its `precall` and `postcall` policies are composed as described here [link concepts.callpolicies `CallPolicies`].][default_call_policies]]
12 namespace boost { namespace python
14 template <size_t arg_pos=1, class Base = default_call_policies>
15 struct return_arg : Base
17 static PyObject* postcall(PyObject*, PyObject* result);
18 struct result_converter{ template <class T> struct apply; };
19 template <class Sig> struct extract_return_type : mpl::at_c<Sig, arg_pos>{};
25 [section Class `return_arg` static functions]
26 ``PyObject* postcall(PyObject* args, PyObject* result);``
28 [[Requires][`PyTuple_Check(args) != 0` and `PyTuple_Size(args) != 0`]]
29 [[Returns][PyTuple_GetItem(args,arg_pos-1)]]
32 [section Class template `return_self`]
34 namespace boost { namespace python
36 template <class Base = default_call_policies>
44 C++ module definition:
46 #include <boost/python/module.hpp>
47 #include <boost/python/class.hpp>
48 #include <boost/python/return_arg.hpp>
52 Widget() :sensitive_(true){}
53 bool get_sensitive() const { return sensitive_; }
54 void set_sensitive(bool s) { this->sensitive_ = s; }
63 std::string get_label() const { return label_; }
64 void set_label(const std::string &l){ label_ = l; }
70 using namespace boost::python;
71 BOOST_PYTHON_MODULE(return_self_ext)
73 class_<widget>("Widget")
74 .def("sensitive", &Widget::get_sensitive)
75 .def("sensitive", &Widget::set_sensitive, return_self<>())
78 class_<Label, bases<Widget> >("Label")
79 .def("label", &Label::get_label)
80 .def("label", &Label::set_label, return_self<>())
86 >>> from return_self_ext import *
87 >>> l1 = Label().label("foo").sensitive(false)
88 >>> l2 = Label().sensitive(false).label("foo")