Boost logo

Boost :

Subject: Re: [boost] [move][unique_ptr] c++14 unique_ptr comes to town
From: Peter Dimov (lists_at_[hidden])
Date: 2014-09-02 13:22:34

Ion Gaztañaga wrote:

> On the other hand, with the default_deleter it could be safe to convert
> (maybe if N >= M):
> 4) unique_ptr<T[N]> -> unique_ptr<U[M]>

I don't support this conversion in shared_ptr and have no plans to.
reinterpret_pointer_cast should work though.

> A problem might occure if a user-provided deleter<T[N]> is be convertible
> to deleter<U[]> but it does not properly handle unknown-length arrays.

In general, if deleter<X> is convertible to deleter<Y> but does not handle Y
properly, it might cause problems. So I'm not sure that this case is
extraordinary in this sense.

It's true that these cases are a bit convoluted because, esp. in the
presence of a user-defined pointer type, we need to decide how much to trust
the deleter and how much to override whatever it says WRT conversions. For
instance, let's say unique_ptr<X1,D1> wants to convert to unique_ptr<X2,D2>
and D1::pointer is convertible to D2::pointer and D1 is convertible to D2
_but_ X2 does not have a virtual destructor. Do we disallow the conversion
as we do in the ordinary X1* -> X2* case when using the default deleter, or
do we go ahead? The array case is similar, unique_ptr<X[],D1> ->
unique_ptr<Y[],D2>, X(*)[] is not convertible to Y(*)[] but both D1::pointer
and D1 are convertible to D2::pointer and D2. Legal or not?

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