[C++-sig] shared_ptr converters
David Abrahams
dave at boost-consulting.com
Mon Apr 21 17:24:49 CEST 2003
Nicodemus <nicodemus at globalite.com.br> writes:
> David Abrahams wrote:
>
>>Nicodemus <nicodemus at globalite.com.br> writes:
>> 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&.
>>
>
> You mean that a function that receives a shared_ptr<X>& wouldn't work?
> Because the following does:
>
> int Test(boost::shared_ptr<A>& a)
> {
> return a->f();
> } >>> from test import *
> >>> a = New()
> >>> Test(a)
> 1
>
> Or am I misunderstood your response?
Yes, my response was badly-phrased. I should've said: if you don't
specify shared_ptr<X>, you won't be able to pass an X object
_constructed from Python_ to a function expecting shared_ptr<X>&:
>>> a = A()
>>> Test(a)
Traceback...
> If the only drawback is not being
> able to expose member functions of the shared_ptr as methods of the
> wrapped object
And also not being able to detach the C++ object from the python
object:
int Detach(boost::shared_ptr<A>& a)
{
a.reset();
}
> I think it is acceptable for Pyste to do the more
> common thing, since this is a rare use case anyway. 8)
I agree.
--
Dave Abrahams
Boost Consulting
www.boost-consulting.com
More information about the Cplusplus-sig
mailing list