[C++-sig] Is there a way to automatically convert a smart_ptr to a held_type (try 2)
Allen Bierbaum
abierbaum at gmail.com
Thu Sep 7 20:32:45 CEST 2006
On 9/7/06, Alex Mohr <amohr at pixar.com> wrote:
> > The non-obvious part of this for me is:
> >
> > - Does this mean that I now need to explicitly wrap (expose using
> > bp::class_ ) all the ref_ptr<> types?
> >
> > I haven't had to do that thus far because it was handled internally
> > somehow because I used it has the held_type for all my classes. If I
> > expose them manually do I run the risk of breaking any of the
> > held_type functionality?
>
> I'm not sure what you mean... If ref_ptr<T> is the held type for T,
> then just provide __eq__ in terms of ref_ptr<T>...
>
> template <class T>
> static bool ref_ptr_eq(ref_ptr<T> const &self, ref_ptr<T> const &other)
> {
> return self == other;
> }
>
> class_<T, ... ref_ptr<T> ... >(...)
> .def("__eq__", ref_ptr_eq<T>)
> ;
>
> Am I misunderstanding your situation?
Ahhh....
No I see what you are meaning. So I need the __eq__ op on the class
itself. Ok. That makes more sense. I thought I may have to wrap the
ref_ptr<T> as a class a and put the __eq__ op on it.
Something like:
class_<ref_ptr<T>, ..>(..)
.def("__eq__", ref_ptr_eq<T>)
;
Thanks for the feedback. I will try your method out and reply to the
list with the results so other people following along can see what
ended up working.
Thanks again,
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