Fwd: [PATCH][GSoC] Extend shared_ptr to support arrays

Fan You youfan.noey@gmail.com
Mon Jun 15 02:23:00 GMT 2015


---------- Forwarded message ----------
From: Fan You <youfan.noey@gmail.com>
Date: 2015-06-14 23:45 GMT+08:00
Subject: Re: [PATCH][GSoC] Extend shared_ptr to support arrays
To: Jonathan Wakely <jwakely@redhat.com>
Cc: Tim Shen <timshen@google.com>, gcc-patches
<gcc-patches@gcc.gnu.org>, libstdc++ <libstdc++@gcc.gnu.org>


This is the revised patch.

Bootstrapped and Tested on Darwin 10.9.4. with testsuite 20_util/*

Alternatively:

__shared_ptr<libfund<_Tp>> : private __shared_ptr<std::remove_extent<_Tp>>

to prevent changing everything once __shared_ptr<_Tp> has changed.

Any advice?



2015-06-12 17:04 GMT+08:00 Jonathan Wakely <jwakely@redhat.com>:
>
> 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
> simply:
>
> +      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.
>
>
> Yes.
>
> 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>
>
>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: a.patch
Type: application/octet-stream
Size: 29130 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/libstdc++/attachments/20150615/e8f95f3d/attachment.obj>


More information about the Libstdc++ mailing list