This is the mail archive of the
libstdc++@gcc.gnu.org
mailing list for the libstdc++ project.
Re: [PATCH][GSoC] Extend shared_ptr to support arrays
- From: Tim Shen <timshen at google dot com>
- To: Fan You <youfan dot noey at gmail dot com>
- Cc: Jonathan Wakely <jwakely at redhat dot com>, "libstdc++" <libstdc++ at gcc dot gnu dot org>
- Date: Mon, 22 Jun 2015 21:19:47 -0700
- Subject: Re: [PATCH][GSoC] Extend shared_ptr to support arrays
- Authentication-results: sourceware.org; auth=none
- References: <CALvpekGQvTp2zRz65cnP+Ex7TKHQygdrYkqo5nUKGJ3bLQj8ww at mail dot gmail dot com> <CAG4ZjNkEPsJd4Crx1xtp4ZvJ-xFGJ5aaR8qb+A7aVMi++wKRtw at mail dot gmail dot com> <20150612090414 dot GP12728 at redhat dot com> <CALvpekG4+YxSVz+jm_quo20=2bWYXnkBFrjDyBu6eYXW4YarHQ at mail dot gmail dot com> <20150615093829 dot GA21485 at redhat dot com> <CALvpekE2a8qi8qRjdzsDOi2OCRJw_ccYd1CrL6z68rLFW0fK0g at mail dot gmail dot com> <20150616132839 dot GA13009 at redhat dot com> <CALvpekFiRrz2UHTvGh+aqnkQPdL-Y=O-vRUXhxwVs-Wz+5v-RA at mail dot gmail dot com> <CAG4ZjNnyp7Tax3CU0BAnbR0DSo6Xc+z8S7+3BSkYSyPpUpyu6g at mail dot gmail dot com>
On Sun, Jun 21, 2015 at 3:50 AM, Tim Shen <timshen@google.com> wrote:
> Quickly looked at __shared_ptr<__libfund_v1<_Tp>, _Lp>; will look at
> the rest parts later.
All suggestions apply for all occursions, not just for the quoted code.
+ // helpers for std::experimental::enable_shared_from_this
+
+ template<typename _Tp, _Lock_policy _Lp = __default_lock_policy>
+ struct __helper_for_experimental_enable_shared
+ {
+ void _Call_M_assign(__weak_ptr<__libfund_v1<_Tp>, _Lp>& __wp,
+ _Tp* __ptr,
+ const __shared_count<_Lp>& __refcount)
+ { __wp._M_assign(__ptr, __refcount); }
+ };
Make the function it static; Suggested class name: __weak_ptr_friend,
function name _S_assign.
+ // Used by __enable_shared_from_this.
+ void
+ _M_assign(_Tp* __ptr, const __shared_count<_Lp>& __refcount) noexcept
+ {
+ _M_ptr = __ptr;
+ _M_refcount = __refcount;
+ }
element_type* __ptr?
Also need a _Compatible; possible implementation:
template<typename _From_type, typename _To_type>
struct __sp_compatible_helper
{ static constexpr bool value = std::is_convertible<_From_type*,
_To_type*>::value; };
template<size_t _Nm, typename _Tp>
struct __sp_compatible_helper<_Tp[_Nm], _Tp[]>
{ static constexpr bool value = true; };
...
template<typename _Tp1>
using _Compatible = typename std::enable_if<__sp_compatible<_Tp1,
_Tp>::value>::type;
+ template<typename _Tp1, typename _Tp2>
+ inline bool
+ operator<(const shared_ptr<_Tp1>& __a,
+ const shared_ptr<_Tp2>& __b) noexcept
+ {
+ using _Tp1_RE = typename remove_extent<_Tp1>::type;
+ using _Tp2_RE = typename remove_extent<_Tp2>::type;
+ using _CT = typename std::common_type<_Tp1_RE*, _Tp2_RE*>::type;
+ return std::less<_CT>()(__a.get(), __b.get());
+ }
using _Tp1_RE = typename shared_ptr<_Tp1>::element_type;
+ // 8.2.1.3, shared_ptr casts
+ template<typename _Tp, typename _Tp1>
+ inline shared_ptr<_Tp>
+ static_pointer_cast(const shared_ptr<_Tp1>& __r) noexcept
+ { shared_ptr<_Tp>(__r, static_cast<typename
shared_ptr<_Tp>::element_type*>(__r.get())); }
+
Missing "return". You can turn on -Wsystem-headers to check for warnings.
--
Regards,
Tim Shen