This answer cites N4082, which shows that the upcoming changes to std::shared_ptr
will allow both T[]
and T[N]
variants:
Unlike the
unique_ptr
partial specialization for arrays, bothshared_ptr<T[]>
andshared_ptr<T[N]>
will be valid and both will result indelete[]
being called on the managed array of objects.template<class Y> explicit shared_ptr(Y* p);
Requires:
Y
shall be a complete type. The expressiondelete[] p
, whenT
is an array type, ordelete p
, whenT
is not an array type, shall be well-formed, shall have well defined behavior, and shall not throw exceptions. WhenT
isU[N]
,Y(*)[N]
shall be convertible toT*
; whenT
isU[]
,Y(*)[]
shall be convertible toT*
; otherwise,Y*
shall be convertible toT*
.
Unless I'm mistaken, a Y(*)[N]
could only be formed by taking the address of an array, which clearly can't be owned or deleted by a shared_ptr
. I also don't see any indication that N
is used in any way to enforce the size of the managed object.
What is the motivation behind allowing the T[N]
syntax? Does it yield any actual benefit, and if so, how is it used?