...one of the most highly
regarded and expertly designed C++ library projects in the
world.
— Herb Sutter and Andrei
Alexandrescu, C++
Coding Standards
Boost.PythonHeader
|
return_arg
and return_self
instantiations are
models of CallPolicies which return the
specified argument parameter (usually *this
) of a wrapped
(member) function.
return_arg
Parameter | Requirements | Description | Default |
---|---|---|---|
arg_pos |
A positive compile-time constant of type
std::size_t . |
the position of the argument to be returned. | 1 |
Base |
A model of 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 CallPolicies. |
default_call_policies |
return_arg
synopsisnamespace boost { namespace python { templatestruct return_arg : Base { static PyObject* postcall(PyObject*, PyObject* result); struct result_converter{ template struct apply; }; template struct extract_return_type : mpl::at_c {}; }; }}
return_arg
static functionsPyObject* postcall(PyObject* args, PyObject* result);
PyTuple_Check(args)
!= 0
and PyTuple_Size(args) != 0
PyTuple_GetItem(args,arg_pos-1)
return_self
return_self
synopsis:namespace boost { namespace python { templatestruct return_self : return_arg<1,Base> {}; }}
#include#include #include struct Widget { Widget() :sensitive_(true){} bool get_sensitive() const { return sensitive_; } void set_sensitive(bool s) { this->sensitive_ = s; } private: bool sensitive_; }; struct Label : Widget { Label() {} std::string get_label() const { return label_; } void set_label(const std::string &l){ label_ = l; } private: std::string label_; }; using namespace boost::python; BOOST_PYTHON_MODULE(return_self_ext) { class_ ("Widget") .def("sensitive", &Widget::get_sensitive) .def("sensitive", &Widget::set_sensitive, return_self<>()) ; class_
>>> from return_self_ext import * >>> l1 = Label().label("foo").sensitive(false) >>> l2 = Label().sensitive(false).label("foo")
Revised 19 July, 2003
© Copyright Dave Abrahams and Nikolay Mladenov 2003.