|
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:
>> https://github.com/jgonggrijp/rich-typed-pointers
> [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,...tn)
>
> 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
declaration).
Thanks for the suggestion though!
-Julian
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk