[C++-sig] Re: New-style polymorphism
David Abrahams
dave at boost-consulting.com
Mon Jul 26 18:44:25 CEST 2004
I forgot one thing:
David Abrahams <dave at boost-consulting.com> writes:
> I just checked in changes that improve the way we can wrap classes
> with virtual functions in Boost.Python. This is essentially what's
> described in
> http://www.boost.org/libs/python/todo.html#base-class-for-virtual-function-callback-wrappers
>
>
> The differences are most apparent if you compare
> libs/python/test/polymorphism.cpp and
> libs/python/test/polymorphism2.cpp.
>
> * you no longer need an initial "self" argument to yourconstructor.
> Instead you derive your class X from wrapper<X> (I'm looking for
> better names for that base class)
>
> * You no longer need to define a special "default" member function
> for the default behavior, and you only have to pass one member
> function pointer to "def()"
>
> * You no longer need to use call_method; you instead ask the
> wrapper<X> base class for the method override, and then call that
> instead. If there's no override, you call the default directly.
> On some broken compilers you may need to use
> call<result_type>(...) args for some of the calls (always on
> vc6/7, for reference return types only on some other compielrs).
> Most other reasonably conforming compilers will convert the result
> of calling the override directly into the function's return type.
>
> * It should be much faster in the case where you have a default
> implementation that isn't overridden in Python, because you'll
> usually not have to enter the Python interpreter.
>
> * Many problems with dangling references have been eliminated,
> because you don't have to take a round-trip through Python. You
> can wrap virtual functions that return char const* !
* A C++ pointer or reference to a polymorphic T created from
Python (one that is actually also a wrapper<T>) can be
converted back to Python without creating a new Python object.
--
Dave Abrahams
Boost Consulting
http://www.boost-consulting.com
More information about the Cplusplus-sig
mailing list