p0497r0:
Incorrect constraint for shared_ptr construction from unique_ptr
[...]
Based on implementation experience I believe the correct form is:
Remark: This constructor shall not participate in overload resolution unless Y*
is compatible with T*
and unique_ptr<Y, D>::pointer
is convertible to element_type*
.
The "compatible with" check prevents undesirable conversions from unique_ptr<T[]>
to shared_ptr<T>
and the "convertible to" check ensures that the result of unique_ptr<Y, D>::get()
can be stored in the shared_ptr
and returned by shared_ptr<T>::get()
.
In other words, this was intentionally made invalid just because it shouldn't be valid, not simply a side effect of other changes.
Which makes sense to me. shared_ptr<T>
is likely to be read by other programmers as pointing to only one T
object. Requiring programmers to use shared_ptr<T[]>
when they want multiple T
objects leads to more readable code.
Note: this correct form is not in the standard. The rationale, however, is in part a comment on what is in the standard.