Boost logo

Boost :

From: Larry Evans (jcampbell3_at_[hidden])
Date: 2002-09-02 15:41:17


Peter Dimov wrote:

>From: "Eric Woodruff" <Eric.Woodruff_at_[hidden]>
>
>
>>Yes, of course, I implemented it with operator shared_ptr<T> () const. The
>>problem is this:
>>
>>shared_ptr<AbstractType> someMethod () {
>> return New<ConcreteType> (p1, p2, p3);
>>}
>>
>>
>
>You can use
>
>template<class Y> operator shared_ptr<Y>() const;
>
>but actually it seems to me that the above should work even with a
>non-templated operator. This is the auto_ptr_ref idiom that somehow manages
>to sneak two user-defined conversions:
>
>auto_ptr<X> someMethod()
>{
> return auto_ptr<X>(new X);
>}
>
>goes through operator auto_ptr_ref(). Of course some compilers frown at it.
>
>
More explicitly, do you mean:

  auto_ptr<ConcreteType> New<ConcreteType>::someMethod()
    { return auto_ptr<ConcreteType>( new ConcreteType(p1,p2,p3));}

And then:

  auto_ptr<ConcreteType> --converted to--> auto_ptr_ref<AbstractType>
     via auto_ptr<ConcreteType>::operator auto_ptr_ref<AbstractType>()

and then:

  auto_ptr_ref<AbstractType> --converted to-->auto_ptr<AbstractType>
    via auto_ptr<AbstractType>::auto_ptr(auto_ptr_ref<AbstractType>)

and finally, the auto_ptr<AbstractType> is used to created the
shared_ptr<AbstractType>?


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk