[C++-sig] shared_ptr converters

David Abrahams dave at boost-consulting.com
Thu Apr 17 04:30:00 CEST 2003

Nicodemus <nicodemus at globalite.com.br> writes:

> David Abrahams wrote:
>>In the meantime, you can do this horrible thing:
>>    objects::class_value_wrapper<
>>        shared_ptr<A>
>>      , objects::make_ptr_instance<A, objects::pointer_holder<shared_ptr<A>,A> >
>>    >();
>>        Which will register a to_python converter for shared_ptr<A>.
> Hmm, no problem. Thanks for the help!
> I will make Pyste generate this code instead of the usual "class_<X,
> boost::shared_ptr<X> >", at least until the necessary changes in
> Boost.Python are made. 8)

One is not, in general, a substitute for the other.  If you don't use
shared_ptr<Y> in your class_<X, ...> (where X may be the same as Y)
then instances of X constructed from Python will not be held by
shared_ptr<Y>.  Whether or not that is important anymore is, of
course, debatable, especially now that we have all the special
shared_ptr treatment in Boost.Python.  

However, there is one significant difference: if you don't specify
shared_ptr<Y> then you will not be able to pass a Python X object as a
shared_ptr<Y>& argument.  Among other things that means you will not
be able to expose member functions of the shared_ptr as methods of the
wrapped X (see Raoul Gough's recent postings about proxies).  You will
still be able to pass a Python X object as shared_ptr<X>,
shared_ptr<Y>, shared_ptr<X> const&, or shared_ptr<Y> const&.


Dave Abrahams
Boost Consulting

More information about the Cplusplus-sig mailing list