[PATCH][GSoC] Extend shared_ptr to support arrays

Jonathan Wakely jwakely@redhat.com
Fri Jun 12 09:04:00 GMT 2015

On 11/06/15 23:43 -0700, Tim Shen wrote:
>+      using element_type = _Tp[N];
>using element_type = typename std::remove_extent_t<_Tp>; ?

Well at that point in the file we're inside the
__shared_ptr<__libfund_v1<_Tp[N]> specialization, so it could be

+      using element_type = _Tp;

However, if we combine some or all of the partial specializations into
one, as I suggested, then it would become simply:

  using element_type = std::remove_extent_t<_Tp>;

(Without the 'typename', although for this to work the new partial
specializations need to be surrounded in #if __cplusplus >= 201402L,
otherwise the remove_extent_t alias is no available.)

This is a good example of why I think we should combine the very
similar specializations, and then use helper traits to define the
parts that vary depending on _Tp, instead of duplicating the entire
class template.

>> using _Deleter_type = typename conditional<is_array<_Tp>::value,
>>       _Normal_deleter, _Array_deleter>::type;
>Sadly std::default_delete doesn't support _Tp[N]. It will also works
>to create a std::default_delete-ish helper trait, with _Tp[N]
>specialized to `delete []` as well.


Another point I missed in my review is that 'N' is not a reserved
identifier, it needs to be changed to _Nm or something else in the
implementation namespace, so that it still works even if users do:

#define N  "Boom!" :-P
#include <experimental/memory>

More information about the Libstdc++ mailing list