Boost C++ Libraries

...one of the most highly regarded and expertly designed C++ library projects in the world. Herb Sutter and Andrei Alexandrescu, C++ Coding Standards

This is the documentation for an old version of Boost. Click here to view this page for the latest version.
PrevUpHomeNext

Why is my automatic to-python conversion not being found?

Niall Douglas provides these notes:

If you define custom converters similar to the ones shown above the def_readonly() and def_readwrite() member functions provided by boost::python::class_ for direct access to your member data will not work as expected. This is because def_readonly("bar",&foo::bar) is equivalent to:

.add_property("bar", make_getter(&foo::bar, return_internal_reference()))

Similarly, def_readwrite("bar",&foo::bar) is equivalent to:

.add_property("bar", make_getter(&foo::bar, return_internal_reference()),
                   make_setter(&foo::bar, return_internal_reference())

In order to define return value policies compatible with the custom conversions replace def_readonly() and def_readwrite() by add_property(). E.g.:

.add_property("bar", make_getter(&foo::bar, return_value_policy<return_by_value>()),
                   make_setter(&foo::bar, return_value_policy<return_by_value>()))

PrevUpHomeNext