Boost C++ Libraries Home Libraries People FAQ More

PrevUpHomeNext

ptr.hpp

Introduction
Functions
Class template pointer_wrapper
Class template pointer_wrapper types
Class template pointer_wrapper constructors and destructor
Class template pointer_wrapper observer functions
Metafunctions
Class template is_pointer_wrapper
Class template unwrap_pointer
Example

<boost/python/ptr.hpp> defines the ptr() function template, which allows users to specify how to convert C++ pointer values to python in the context of implementing overridable virtual functions, invoking Python callable objects, or explicitly converting C++ objects to Python. Normally, when passing pointers to Python callbacks, the pointee is copied to ensure that the Python object never holds a dangling reference. To specify that the new Python object should merely contain a copy of a pointer p, the user can pass ptr(p) instead of passing p directly. This interface is meant to mirror the use of boost::ref(), which can be similarly used to prevent copying of referents.

ptr(p) returns an instance of pointer_wrapper<>, which can be detected using the is_pointer_wrapper<> metafunction; unwrap_pointer<> is a metafunction which extracts the original pointer type from a pointer_wrapper<>. These classes can be thought of as implementation details.


PrevUpHomeNext