Boost logo

Boost :

Subject: Re: [boost] [interest] rich-typed smart pointers
From: Julian Gonggrijp (j.gonggrijp_at_[hidden])
Date: 2013-10-05 17:26:09

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>, but it
can't know in advance that there is a Base. It is not possible to just
friend-declare owner_ptr<U> for all U, either, because C++ only allows
complete types as friends (there's no such thing as a templated friend

Thanks for the suggestion though!


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