Boost logo

Boost :

Subject: Re: [boost] [interest] rich-typed smart pointers
From: Larry Evans (cppljevans_at_[hidden])
Date: 2013-10-05 21:14:38

On 10/05/13 16:26, Julian Gonggrijp wrote:
> Larry Evans wrote:
>> [snip]
>> If there were a templated owned_ptr CTOR:
>> template<typename Derived>
>> owner_ptr (owner_ptr<Derived> && source) : pointer(source.pointer) {
>> source.pointer = nullptr;
>> }
>> wouldn't that eliminate the need for the make_dynamic templated function?
>> Just wondering. I haven't tried it, but I'd guess it would work because
>> the ownd_ptr<Derived> could be constructed with the:
>> make<Derived>(t1,t2,
>> and then the templated owned_ptr CTOR would then convert that to the
>> base class?
> I agree this would be great, but unfortunately it appears it can't be done.
> owner_ptr<Derived> would have to friend-declare owner_ptr<Base>,
I don't see why. AFAICT, you'd require *fewer* friend declarations, not
more( you wouldn't need the:

     template <class U1, class U2, class ... Us>
     friend owner_ptr<U1> make_dynamic (Us&& ...);

the only friend needed would the existing:

     template <class U, class ... Us>
     friend owner_ptr<U> make (Us&& ...);

that's because the proposed templated constructor would have the same
access as the existing:

     owner_ptr (owner_ptr && source);

CTOR, i.e. public. IOW, with the proposed templated CTOR, the
following example code creating an owner_ptr<Base> should work,

     ( make<Derived>
       ( DerivedInit0()
       , DerivedInit1()
       . DerivedInitN()

Where DeriveInit0, DerivedInit1, ... DerivedInitN
are the types of the args to the CTOR for Derived.

Is there some reason why the above example code would
*not* compile, given then proposed templated CTOR?


Boost list run by bdawes at, gregod at, cpdaniel at, john at