[C++-sig] Is there a way to automatically convert a smart_ptr to a held_type (try 2)
Allen Bierbaum
abierbaum at gmail.com
Wed Sep 6 22:50:56 CEST 2006
On 9/6/06, Alex Mohr <amohr at pixar.com> wrote:
> > I am sorting through this code right now. Am I missing something or
> > is there no documentation in the reference guide about how to register
> > a converter directly with the registry?
>
> No, but the code I posted does it in the constructor.
>
> > Additionally, I was looking at the documentation for
> > implicitly_convertible and I am wondering why I can't just use that in
> > my case.
> >
> > I want to call:
> >
> > setObject(ptr<Base> val)
> >
> > with a NoneType. And I have all my objects (ie. Base) wrapped and set
> > with held types of ref_ptr<>'s. RefPtr's are implicitly convertible
> > to ptr<>'s, so If I register this with boost.python using:
> >
> > bp::implicitly_convertible< ret_ptr<Base>, ptr<Base> >();
> >
> > Then shouldn't boost.python be able to convert NoneType -->
> > ref_ptr<Base> --> ptr<Base> ? From the documentation in
> > implicitly_convertible it seems like this should be the case. But I
> > have to admit I have not found the place in the boost.python code
> > where it handles the case of taking a NoneType and automatically
> > converting it into a NULL smart pointer to start with.
>
> Sure -- if your types meet those requirements, then that should work.
> The rvalue converters I posted are more general. implicitly_convertible
> just registers an rvalue converter using the same underlying mechanism.
>
> From your message, I was under the impression that default-constructing
> one of your smart pointers would not produce the desired "null" value.
A default construction of the RefPtr Type should, but using
implicitly_convertible didn't work. It acted like it didn't know that
there was an option to convert through the implicit chains.
I have now implemented something based on the code you posted and am
working on testing it. Hopefully it will work out. I will let you
kno.
-Allen
>
> Alex
> _______________________________________________
> C++-sig mailing list
> C++-sig at python.org
> http://mail.python.org/mailman/listinfo/c++-sig
>
More information about the Cplusplus-sig
mailing list