diff --git a/doc/v2/has_back_reference.html b/doc/v2/has_back_reference.html index ab92e353..58932644 100644 --- a/doc/v2/has_back_reference.html +++ b/doc/v2/has_back_reference.html @@ -63,7 +63,7 @@

Introduction

<boost/python/has_back_reference.hpp> defines the - traits class template has_back_reference<>, which can + predicate metafunction has_back_reference<>, which can be specialized by the user to indicate that a wrapped class instance holds a PyObject* corresponding to a Python object.

@@ -82,28 +82,34 @@ namespace boost { namespace python { template<class WrappedClass> class has_back_reference { - static unspecified value = false; + typedef unspecified type; }; }} - -

A "traits - class" which is inspected by Boost.Python to determine how wrapped - classes can be constructed.

+

A " + metafunction" which is inspected by Boost.Python to determine how + wrapped classes can be constructed.

-
value is an integral constant convertible to bool of - unspecified type.
+
type::value is an integral constant convertible to bool + of unspecified type.
-
Specializations may substitute a value convertible to - true for value iff for each invocation of - class_<WrappedClass>::def(init<type-sequence... - >()), there exists a corresponding constructor - WrappedClass::WrappedClass(PyObject*, type-sequence... - ). If such a specialization exists, the - WrappedClass constructors will be called with a "back +
Specializations may substitute a typedef with a nested + value convertible to + true for type iff for each invocation of + class_<WrappedClass>::def(init< + type-sequence...>()) and the implicitly provided + copy constructor (unless it is + noncopyable), there exists a corresponding constructor + WrappedClass::WrappedClass(PyObject*,  + type-sequence...). If such a specialization exists, + the WrappedClass constructors will be called with a "back reference" pointer to the corresponding Python object whenever they are - invoked from Python.
+ invoked from Python. The easiest way to provide this typedef is to + inherit from mpl::true_, or to + typedef mpl::true_ type. Alternatively, the specialization + may provide its own metafunction. +

Example

@@ -117,18 +123,20 @@ namespace boost { namespace python #include <boost/shared_ptr.hpp> using namespace boost::python; +using boost::shared_ptr; struct X { X(PyObject* self) : m_self(self), m_x(0) {} X(PyObject* self, int x) : m_self(self), m_x(x) {} + X(PyObject* self, X const& other) : m_self(self), m_x(other.m_x) {} handle<> self() { return handle<>(borrowed(m_self)); } int get() { return m_x; } void set(int x) { m_x = x; } PyObject* m_self; - int x; + int m_x; }; // specialize has_back_reference for X @@ -137,8 +145,8 @@ namespace boost { namespace python template <> struct has_back_reference<X> { - enum { value = true; } - } + typedef mpl::true_ type; + }; }} struct Y @@ -148,10 +156,11 @@ struct Y int get() { return m_x; } void set(int x) { m_x = x; } - int x; + int m_x; }; -boost::shared_ptr<Y> Y_self(boost::shared_ptr<Y> self) const { return self; } +boost::shared_ptr<Y> +Y_self(boost::shared_ptr<Y> self) { return self; } BOOST_PYTHON_MODULE(back_references) {