[C++-sig] Boost.Python v2: ** important **

David Abrahams dave at boost-consulting.com
Mon Sep 16 06:39:28 CEST 2002


* Boost.Python v2 and MPL have both been moved completely to the main trunk
of Boost CVS. To get a CVS snapshot that reflects the current state of the
world:

    cd <boost-root-directory>
    cvs update -P -d -A .

If you've been using Boost.Python v2, you've been using the mpl-development
branch of boost/mpl. That will no longer work. If you don't take the steps
above the next time you update you will get lots of errors and no happy
success with compilation ;-)

* Joel has just finished adding what I hope will be the final code-breaking
changes to Boost.Python v2 before its release early next month. These are
still on a branch in the CVS for the time being (just to give you time to
test your code with the current CVS state), but they will be merged
sometime on Tuesday.

Summary:

1. When specifying constructors, there is a new format:

     init<...args..., optional< ...args...> >("docstring")[call_policies()]

Of course any of args, optional, "docstring" and [call_policies()] may be
ommitted.

2. The def_init() function is going away. It is replaced by a def()
overload which accepts init<...>. Thus:

    // default constructor with docstring
    class_<Y>("Y", init<>("doc of Y init"))
        .def("get_state", &Y::get_state)
        .def(init<int, optional<char, std::string, double> >("doc of
init"))
        .def(init<X*>()[with_custodian_and_ward<1,2>()])
        ;

3. A similar interface applies to the default argument feature:

  X* foo(Y& y, char b = 'D', std::string c = "default", double d = 0.0);

  // Generate overloads for 1-4 parameters
  BOOST_PYTHON_FUNCTION_OVERLOADS(foo_overloads, foo, 1, 4)

    ...
    def("foo", foo, foo_overloads("about
foo")[return_internal_reference<>()])

-Dave

-----------------------------------------------------------
           David Abrahams * Boost Consulting
dave at boost-consulting.com * http://www.boost-consulting.com








More information about the Cplusplus-sig mailing list