[PATCH][GSoC] Extend shared_ptr to support arrays

Tim Shen timshen@google.com
Sun Jun 21 18:41:00 GMT 2015


On Sun, Jun 21, 2015 at 10:44 AM, Fan You <youfan.noey@gmail.com> wrote:
> passing the __lib_fund version should be fine here, since the
> __base_type will judg while doing _M_ptr = __r._M_prt.

This is correct only for now, but who knows what's gonna happen in the
future? Being more defensive and introduce less dependency (not let
shared_ptr depend on libfund_v1) is usually good.

>> Please be aware of spaces surrounding operators:
>> _GLIBCXX_DEBUG_ASSERT(get() != 0 && i >= 0);
>
> what does this mean?

Compare string "get() !=0" against "get() != 0", and " i>=0" against
"i >= 0", and see what you find :)

> Is it a good idea to change _Convertible alias to _Compatible in base.h?
>
>       template <typename _Tp1>
>         struct _is_compatible
>         {
>           bool value = (is_array<_Tp1>::value && is_array<_Tp>::value
>                                  && (is_same<typename
> remove_extent<_Tp1>::type, element_type>::value))
>                                || (is_convertible<_Tp1, element_type*>::value);
>         };
>
>       template<typename _Tp1>
>         using _Compatible
>           = typename enable_if<_is_compatible<_Tp1>().value>::type;

"or Y is U[N] and T is U cv []", not vice versa. So:
    std::experimental::shared_ptr<int[]> sp(new int[2]);
    std::experimental::shared_ptr<int[2]> spa(sp);
...shouldn't compile. You probably need some specialization to do this.

_is_compatible -> __sp_is_compatible seems to be better.


-- 
Regards,
Tim Shen



More information about the Libstdc++ mailing list