49 #ifndef _SHARED_PTR_BASE_H
50 #define _SHARED_PTR_BASE_H 1
57 #if __cplusplus > 201703L
61 namespace std _GLIBCXX_VISIBILITY(default)
63 _GLIBCXX_BEGIN_NAMESPACE_VERSION
65 #if _GLIBCXX_USE_DEPRECATED
66 #pragma GCC diagnostic push
67 #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
68 template<
typename>
class auto_ptr;
69 #pragma GCC diagnostic pop
79 virtual char const*
what() const noexcept;
86 __throw_bad_weak_ptr()
89 using __gnu_cxx::_Lock_policy;
90 using __gnu_cxx::__default_lock_policy;
91 using __gnu_cxx::_S_single;
92 using __gnu_cxx::_S_mutex;
93 using __gnu_cxx::_S_atomic;
96 template<_Lock_policy _Lp>
101 enum { _S_need_barriers = 0 };
105 class _Mutex_base<_S_mutex>
106 :
public __gnu_cxx::__mutex
112 enum { _S_need_barriers = 1 };
115 template<_Lock_policy _Lp = __default_lock_policy>
116 class _Sp_counted_base
117 :
public _Mutex_base<_Lp>
120 _Sp_counted_base() noexcept
121 : _M_use_count(1), _M_weak_count(1) { }
124 ~_Sp_counted_base() noexcept
130 _M_dispose() noexcept = 0;
134 _M_destroy() noexcept
142 { __gnu_cxx::__atomic_add_dispatch(&_M_use_count, 1); }
148 _M_add_ref_lock_nothrow();
151 _M_release() noexcept
154 _GLIBCXX_SYNCHRONIZATION_HAPPENS_BEFORE(&_M_use_count);
155 if (__gnu_cxx::__exchange_and_add_dispatch(&_M_use_count, -1) == 1)
157 _GLIBCXX_SYNCHRONIZATION_HAPPENS_AFTER(&_M_use_count);
163 if (_Mutex_base<_Lp>::_S_need_barriers)
165 __atomic_thread_fence (__ATOMIC_ACQ_REL);
169 _GLIBCXX_SYNCHRONIZATION_HAPPENS_BEFORE(&_M_weak_count);
170 if (__gnu_cxx::__exchange_and_add_dispatch(&_M_weak_count,
173 _GLIBCXX_SYNCHRONIZATION_HAPPENS_AFTER(&_M_weak_count);
180 _M_weak_add_ref() noexcept
181 { __gnu_cxx::__atomic_add_dispatch(&_M_weak_count, 1); }
184 _M_weak_release() noexcept
187 _GLIBCXX_SYNCHRONIZATION_HAPPENS_BEFORE(&_M_weak_count);
188 if (__gnu_cxx::__exchange_and_add_dispatch(&_M_weak_count, -1) == 1)
190 _GLIBCXX_SYNCHRONIZATION_HAPPENS_AFTER(&_M_weak_count);
191 if (_Mutex_base<_Lp>::_S_need_barriers)
195 __atomic_thread_fence (__ATOMIC_ACQ_REL);
202 _M_get_use_count() const noexcept
206 return __atomic_load_n(&_M_use_count, __ATOMIC_RELAXED);
210 _Sp_counted_base(_Sp_counted_base
const&) =
delete;
211 _Sp_counted_base& operator=(_Sp_counted_base
const&) =
delete;
213 _Atomic_word _M_use_count;
214 _Atomic_word _M_weak_count;
219 _Sp_counted_base<_S_single>::
222 if (_M_use_count == 0)
223 __throw_bad_weak_ptr();
229 _Sp_counted_base<_S_mutex>::
233 if (__gnu_cxx::__exchange_and_add_dispatch(&_M_use_count, 1) == 0)
236 __throw_bad_weak_ptr();
242 _Sp_counted_base<_S_atomic>::
246 _Atomic_word __count = _M_get_use_count();
250 __throw_bad_weak_ptr();
254 while (!__atomic_compare_exchange_n(&_M_use_count, &__count, __count + 1,
255 true, __ATOMIC_ACQ_REL,
261 _Sp_counted_base<_S_single>::
262 _M_add_ref_lock_nothrow()
264 if (_M_use_count == 0)
272 _Sp_counted_base<_S_mutex>::
273 _M_add_ref_lock_nothrow()
276 if (__gnu_cxx::__exchange_and_add_dispatch(&_M_use_count, 1) == 0)
286 _Sp_counted_base<_S_atomic>::
287 _M_add_ref_lock_nothrow()
290 _Atomic_word __count = _M_get_use_count();
298 while (!__atomic_compare_exchange_n(&_M_use_count, &__count, __count + 1,
299 true, __ATOMIC_ACQ_REL,
306 _Sp_counted_base<_S_single>::_M_add_ref_copy()
311 _Sp_counted_base<_S_single>::_M_release() noexcept
313 if (--_M_use_count == 0)
316 if (--_M_weak_count == 0)
323 _Sp_counted_base<_S_single>::_M_weak_add_ref() noexcept
328 _Sp_counted_base<_S_single>::_M_weak_release() noexcept
330 if (--_M_weak_count == 0)
336 _Sp_counted_base<_S_single>::_M_get_use_count() const noexcept
337 {
return _M_use_count; }
341 template<
typename _Tp, _Lock_policy _Lp = __default_lock_policy>
344 template<
typename _Tp, _Lock_policy _Lp = __default_lock_policy>
347 template<
typename _Tp, _Lock_policy _Lp = __default_lock_policy>
348 class __enable_shared_from_this;
350 template<
typename _Tp>
353 template<
typename _Tp>
356 template<
typename _Tp>
359 template<
typename _Tp>
360 class enable_shared_from_this;
362 template<_Lock_policy _Lp = __default_lock_policy>
365 template<_Lock_policy _Lp = __default_lock_policy>
366 class __shared_count;
370 template<
typename _Ptr, _Lock_policy _Lp>
371 class _Sp_counted_ptr final :
public _Sp_counted_base<_Lp>
375 _Sp_counted_ptr(_Ptr __p) noexcept
379 _M_dispose() noexcept
383 _M_destroy() noexcept
390 _Sp_counted_ptr(
const _Sp_counted_ptr&) =
delete;
391 _Sp_counted_ptr& operator=(
const _Sp_counted_ptr&) =
delete;
399 _Sp_counted_ptr<nullptr_t, _S_single>::_M_dispose() noexcept { }
403 _Sp_counted_ptr<nullptr_t, _S_mutex>::_M_dispose() noexcept { }
407 _Sp_counted_ptr<nullptr_t, _S_atomic>::_M_dispose() noexcept { }
409 template<
int _Nm,
typename _Tp,
410 bool __use_ebo = !__is_final(_Tp) && __is_empty(_Tp)>
411 struct _Sp_ebo_helper;
414 template<
int _Nm,
typename _Tp>
415 struct _Sp_ebo_helper<_Nm, _Tp, true> :
private _Tp
417 explicit _Sp_ebo_helper(
const _Tp& __tp) : _Tp(__tp) { }
418 explicit _Sp_ebo_helper(_Tp&& __tp) : _Tp(
std::move(__tp)) { }
421 _S_get(_Sp_ebo_helper& __eboh) {
return static_cast<_Tp&
>(__eboh); }
425 template<
int _Nm,
typename _Tp>
426 struct _Sp_ebo_helper<_Nm, _Tp, false>
428 explicit _Sp_ebo_helper(
const _Tp& __tp) : _M_tp(__tp) { }
429 explicit _Sp_ebo_helper(_Tp&& __tp) : _M_tp(
std::move(__tp)) { }
432 _S_get(_Sp_ebo_helper& __eboh)
433 {
return __eboh._M_tp; }
440 template<
typename _Ptr,
typename _Deleter,
typename _Alloc, _Lock_policy _Lp>
441 class _Sp_counted_deleter final :
public _Sp_counted_base<_Lp>
443 class _Impl : _Sp_ebo_helper<0, _Deleter>, _Sp_ebo_helper<1, _Alloc>
445 typedef _Sp_ebo_helper<0, _Deleter> _Del_base;
446 typedef _Sp_ebo_helper<1, _Alloc> _Alloc_base;
449 _Impl(_Ptr __p, _Deleter __d,
const _Alloc& __a) noexcept
450 : _M_ptr(__p), _Del_base(
std::move(__d)), _Alloc_base(__a)
453 _Deleter& _M_del() noexcept {
return _Del_base::_S_get(*
this); }
454 _Alloc& _M_alloc() noexcept {
return _Alloc_base::_S_get(*
this); }
460 using __allocator_type = __alloc_rebind<_Alloc, _Sp_counted_deleter>;
463 _Sp_counted_deleter(_Ptr __p, _Deleter __d) noexcept
464 : _M_impl(__p,
std::move(__d), _Alloc()) { }
467 _Sp_counted_deleter(_Ptr __p, _Deleter __d,
const _Alloc& __a) noexcept
470 ~_Sp_counted_deleter() noexcept { }
473 _M_dispose() noexcept
474 { _M_impl._M_del()(_M_impl._M_ptr); }
477 _M_destroy() noexcept
479 __allocator_type __a(_M_impl._M_alloc());
480 __allocated_ptr<__allocator_type> __guard_ptr{ __a,
this };
481 this->~_Sp_counted_deleter();
490 return __ti ==
typeid(_Deleter)
504 struct _Sp_make_shared_tag
507 template<
typename _Tp,
typename _Alloc, _Lock_policy _Lp>
508 friend class _Sp_counted_ptr_inplace;
510 static const type_info&
511 _S_ti() noexcept _GLIBCXX_VISIBILITY(default)
513 alignas(type_info)
static constexpr
char __tag[
sizeof(type_info)] = { };
514 return reinterpret_cast<const type_info&
>(__tag);
517 static bool _S_eq(
const type_info&) noexcept;
520 template<
typename _Alloc>
521 struct _Sp_alloc_shared_tag
526 template<
typename _Tp,
typename _Alloc, _Lock_policy _Lp>
527 class _Sp_counted_ptr_inplace final :
public _Sp_counted_base<_Lp>
529 class _Impl : _Sp_ebo_helper<0, _Alloc>
531 typedef _Sp_ebo_helper<0, _Alloc> _A_base;
534 explicit _Impl(_Alloc __a) noexcept : _A_base(__a) { }
536 _Alloc& _M_alloc() noexcept {
return _A_base::_S_get(*
this); }
538 __gnu_cxx::__aligned_buffer<_Tp> _M_storage;
542 using __allocator_type = __alloc_rebind<_Alloc, _Sp_counted_ptr_inplace>;
545 template<
typename... _Args>
546 _Sp_counted_ptr_inplace(_Alloc __a, _Args&&... __args)
552 std::forward<_Args>(__args)...);
555 ~_Sp_counted_ptr_inplace() noexcept { }
558 _M_dispose() noexcept
565 _M_destroy() noexcept
567 __allocator_type __a(_M_impl._M_alloc());
568 __allocated_ptr<__allocator_type> __guard_ptr{ __a,
this };
569 this->~_Sp_counted_ptr_inplace();
573 friend class __shared_count<_Lp>;
580 auto __ptr =
const_cast<typename remove_cv<_Tp>::type*
>(_M_ptr());
585 if (&__ti == &_Sp_make_shared_tag::_S_ti()
588 __ti ==
typeid(_Sp_make_shared_tag)
590 _Sp_make_shared_tag::_S_eq(__ti)
597 _Tp* _M_ptr() noexcept {
return _M_impl._M_storage._M_ptr(); }
603 struct __sp_array_delete
605 template<
typename _Yp>
606 void operator()(_Yp* __p)
const {
delete[] __p; }
609 template<_Lock_policy _Lp>
612 template<
typename _Tp>
613 struct __not_alloc_shared_tag {
using type = void; };
615 template<
typename _Tp>
616 struct __not_alloc_shared_tag<_Sp_alloc_shared_tag<_Tp>> { };
619 constexpr __shared_count() noexcept : _M_pi(0)
622 template<
typename _Ptr>
624 __shared_count(_Ptr __p) : _M_pi(0)
628 _M_pi =
new _Sp_counted_ptr<_Ptr, _Lp>(__p);
633 __throw_exception_again;
637 template<
typename _Ptr>
639 : __shared_count(__p)
642 template<
typename _Ptr>
644 : __shared_count(__p, __sp_array_delete{}, allocator<void>())
647 template<
typename _Ptr,
typename _Deleter,
648 typename =
typename __not_alloc_shared_tag<_Deleter>::type>
649 __shared_count(_Ptr __p, _Deleter __d)
650 : __shared_count(__p,
std::
move(__d), allocator<void>())
653 template<
typename _Ptr,
typename _Deleter,
typename _Alloc,
654 typename =
typename __not_alloc_shared_tag<_Deleter>::type>
655 __shared_count(_Ptr __p, _Deleter __d, _Alloc __a) : _M_pi(0)
657 typedef _Sp_counted_deleter<_Ptr, _Deleter, _Alloc, _Lp> _Sp_cd_type;
660 typename _Sp_cd_type::__allocator_type __a2(__a);
662 _Sp_cd_type* __mem = __guard.get();
670 __throw_exception_again;
674 template<
typename _Tp,
typename _Alloc,
typename... _Args>
675 __shared_count(_Tp*& __p, _Sp_alloc_shared_tag<_Alloc> __a,
678 typedef _Sp_counted_ptr_inplace<_Tp, _Alloc, _Lp> _Sp_cp_type;
679 typename _Sp_cp_type::__allocator_type __a2(__a._M_a);
681 _Sp_cp_type* __mem = __guard.get();
682 auto __pi = ::new (__mem)
683 _Sp_cp_type(__a._M_a, std::forward<_Args>(__args)...);
686 __p = __pi->_M_ptr();
689 #if _GLIBCXX_USE_DEPRECATED
690 #pragma GCC diagnostic push
691 #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
693 template<
typename _Tp>
696 #pragma GCC diagnostic pop
700 template<
typename _Tp,
typename _Del>
706 if (__r.get() ==
nullptr)
709 using _Ptr =
typename unique_ptr<_Tp, _Del>::pointer;
710 using _Del2 =
typename conditional<is_reference<_Del>::value,
711 reference_wrapper<typename remove_reference<_Del>::type>,
714 = _Sp_counted_deleter<_Ptr, _Del2, allocator<void>, _Lp>;
715 using _Alloc = allocator<_Sp_cd_type>;
716 using _Alloc_traits = allocator_traits<_Alloc>;
718 _Sp_cd_type* __mem = _Alloc_traits::allocate(__a, 1);
722 _Alloc_traits::construct(__a, __mem, __r.release(),
723 std::forward<_Del>(__r.get_deleter()));
728 explicit __shared_count(
const __weak_count<_Lp>& __r);
731 explicit __shared_count(
const __weak_count<_Lp>& __r, std::nothrow_t);
733 ~__shared_count() noexcept
735 if (_M_pi !=
nullptr)
739 __shared_count(
const __shared_count& __r) noexcept
743 _M_pi->_M_add_ref_copy();
747 operator=(
const __shared_count& __r) noexcept
749 _Sp_counted_base<_Lp>* __tmp = __r._M_pi;
753 __tmp->_M_add_ref_copy();
762 _M_swap(__shared_count& __r) noexcept
764 _Sp_counted_base<_Lp>* __tmp = __r._M_pi;
770 _M_get_use_count() const noexcept
771 {
return _M_pi != 0 ? _M_pi->_M_get_use_count() : 0; }
774 _M_unique() const noexcept
775 {
return this->_M_get_use_count() == 1; }
779 {
return _M_pi ? _M_pi->_M_get_deleter(__ti) :
nullptr; }
782 _M_less(
const __shared_count& __rhs)
const noexcept
786 _M_less(
const __weak_count<_Lp>& __rhs)
const noexcept
791 operator==(
const __shared_count& __a,
const __shared_count& __b) noexcept
792 {
return __a._M_pi == __b._M_pi; }
795 friend class __weak_count<_Lp>;
797 _Sp_counted_base<_Lp>* _M_pi;
801 template<_Lock_policy _Lp>
805 constexpr __weak_count() noexcept : _M_pi(
nullptr)
808 __weak_count(
const __shared_count<_Lp>& __r) noexcept
811 if (_M_pi !=
nullptr)
812 _M_pi->_M_weak_add_ref();
815 __weak_count(
const __weak_count& __r) noexcept
818 if (_M_pi !=
nullptr)
819 _M_pi->_M_weak_add_ref();
822 __weak_count(__weak_count&& __r) noexcept
824 { __r._M_pi =
nullptr; }
826 ~__weak_count() noexcept
828 if (_M_pi !=
nullptr)
829 _M_pi->_M_weak_release();
833 operator=(
const __shared_count<_Lp>& __r) noexcept
835 _Sp_counted_base<_Lp>* __tmp = __r._M_pi;
836 if (__tmp !=
nullptr)
837 __tmp->_M_weak_add_ref();
838 if (_M_pi !=
nullptr)
839 _M_pi->_M_weak_release();
845 operator=(
const __weak_count& __r) noexcept
847 _Sp_counted_base<_Lp>* __tmp = __r._M_pi;
848 if (__tmp !=
nullptr)
849 __tmp->_M_weak_add_ref();
850 if (_M_pi !=
nullptr)
851 _M_pi->_M_weak_release();
857 operator=(__weak_count&& __r) noexcept
859 if (_M_pi !=
nullptr)
860 _M_pi->_M_weak_release();
867 _M_swap(__weak_count& __r) noexcept
869 _Sp_counted_base<_Lp>* __tmp = __r._M_pi;
875 _M_get_use_count() const noexcept
876 {
return _M_pi !=
nullptr ? _M_pi->_M_get_use_count() : 0; }
879 _M_less(
const __weak_count& __rhs)
const noexcept
883 _M_less(
const __shared_count<_Lp>& __rhs)
const noexcept
888 operator==(
const __weak_count& __a,
const __weak_count& __b) noexcept
889 {
return __a._M_pi == __b._M_pi; }
892 friend class __shared_count<_Lp>;
894 _Sp_counted_base<_Lp>* _M_pi;
898 template<_Lock_policy _Lp>
900 __shared_count<_Lp>::__shared_count(
const __weak_count<_Lp>& __r)
903 if (_M_pi !=
nullptr)
904 _M_pi->_M_add_ref_lock();
906 __throw_bad_weak_ptr();
910 template<_Lock_policy _Lp>
912 __shared_count<_Lp>::
913 __shared_count(
const __weak_count<_Lp>& __r, std::nothrow_t)
916 if (_M_pi !=
nullptr)
917 if (!_M_pi->_M_add_ref_lock_nothrow())
921 #define __cpp_lib_shared_ptr_arrays 201611L
927 template<
typename _Yp_ptr,
typename _Tp_ptr>
928 struct __sp_compatible_with
932 template<
typename _Yp,
typename _Tp>
933 struct __sp_compatible_with<_Yp*, _Tp*>
934 : is_convertible<_Yp*, _Tp*>::type
937 template<
typename _Up,
size_t _Nm>
938 struct __sp_compatible_with<_Up(*)[_Nm], _Up(*)[]>
942 template<
typename _Up,
size_t _Nm>
943 struct __sp_compatible_with<_Up(*)[_Nm],
const _Up(*)[]>
947 template<
typename _Up,
size_t _Nm>
948 struct __sp_compatible_with<_Up(*)[_Nm],
volatile _Up(*)[]>
952 template<
typename _Up,
size_t _Nm>
953 struct __sp_compatible_with<_Up(*)[_Nm],
const volatile _Up(*)[]>
958 template<
typename _Up,
size_t _Nm,
typename _Yp,
typename =
void>
959 struct __sp_is_constructible_arrN
963 template<
typename _Up,
size_t _Nm,
typename _Yp>
964 struct __sp_is_constructible_arrN<_Up, _Nm, _Yp, __void_t<_Yp[_Nm]>>
965 : is_convertible<_Yp(*)[_Nm], _Up(*)[_Nm]>::type
969 template<
typename _Up,
typename _Yp,
typename =
void>
970 struct __sp_is_constructible_arr
974 template<
typename _Up,
typename _Yp>
975 struct __sp_is_constructible_arr<_Up, _Yp, __void_t<_Yp[]>>
976 : is_convertible<_Yp(*)[], _Up(*)[]>::type
980 template<
typename _Tp,
typename _Yp>
981 struct __sp_is_constructible;
984 template<
typename _Up,
size_t _Nm,
typename _Yp>
985 struct __sp_is_constructible<_Up[_Nm], _Yp>
986 : __sp_is_constructible_arrN<_Up, _Nm, _Yp>::type
990 template<
typename _Up,
typename _Yp>
991 struct __sp_is_constructible<_Up[], _Yp>
992 : __sp_is_constructible_arr<_Up, _Yp>::type
996 template<
typename _Tp,
typename _Yp>
997 struct __sp_is_constructible
998 : is_convertible<_Yp*, _Tp*>::type
1003 template<
typename _Tp, _Lock_policy _Lp,
1004 bool = is_array<_Tp>::value,
bool = is_void<_Tp>::value>
1005 class __shared_ptr_access
1008 using element_type = _Tp;
1013 __glibcxx_assert(_M_get() !=
nullptr);
1018 operator->() const noexcept
1020 _GLIBCXX_DEBUG_PEDASSERT(_M_get() !=
nullptr);
1026 _M_get() const noexcept
1027 {
return static_cast<const __shared_ptr<_Tp, _Lp>*
>(
this)->get(); }
1031 template<
typename _Tp, _Lock_policy _Lp>
1032 class __shared_ptr_access<_Tp, _Lp, false, true>
1035 using element_type = _Tp;
1038 operator->() const noexcept
1040 auto __ptr =
static_cast<const __shared_ptr<_Tp, _Lp>*
>(
this)->get();
1041 _GLIBCXX_DEBUG_PEDASSERT(__ptr !=
nullptr);
1047 template<
typename _Tp, _Lock_policy _Lp>
1048 class __shared_ptr_access<_Tp, _Lp, true, false>
1051 using element_type =
typename remove_extent<_Tp>::type;
1053 #if __cplusplus <= 201402L
1054 [[__deprecated__(
"shared_ptr<T[]>::operator* is absent from C++17")]]
1058 __glibcxx_assert(_M_get() !=
nullptr);
1062 [[__deprecated__(
"shared_ptr<T[]>::operator-> is absent from C++17")]]
1064 operator->() const noexcept
1066 _GLIBCXX_DEBUG_PEDASSERT(_M_get() !=
nullptr);
1072 operator[](ptrdiff_t __i)
const
1074 __glibcxx_assert(_M_get() !=
nullptr);
1075 __glibcxx_assert(!extent<_Tp>::value || __i < extent<_Tp>::value);
1076 return _M_get()[__i];
1081 _M_get() const noexcept
1082 {
return static_cast<const __shared_ptr<_Tp, _Lp>*
>(
this)->get(); }
1085 template<
typename _Tp, _Lock_policy _Lp>
1087 :
public __shared_ptr_access<_Tp, _Lp>
1090 using element_type =
typename remove_extent<_Tp>::type;
1094 template<
typename _Yp>
1096 =
typename enable_if<__sp_is_constructible<_Tp, _Yp>::value>::type;
1099 template<
typename _Yp,
typename _Res =
void>
1100 using _Compatible =
typename
1101 enable_if<__sp_compatible_with<_Yp*, _Tp*>::value, _Res>::type;
1104 template<
typename _Yp>
1105 using _Assignable = _Compatible<_Yp, __shared_ptr&>;
1108 template<
typename _Yp,
typename _Del,
typename _Res = void,
1109 typename _Ptr =
typename unique_ptr<_Yp, _Del>::pointer>
1110 using _UniqCompatible = __enable_if_t<__and_<
1111 __sp_compatible_with<_Yp*, _Tp*>,
1112 is_convertible<_Ptr, element_type*>,
1113 is_move_constructible<_Del>
1117 template<
typename _Yp,
typename _Del>
1118 using _UniqAssignable = _UniqCompatible<_Yp, _Del, __shared_ptr&>;
1122 #if __cplusplus > 201402L
1123 using weak_type = __weak_ptr<_Tp, _Lp>;
1126 constexpr __shared_ptr() noexcept
1127 : _M_ptr(0), _M_refcount()
1130 template<
typename _Yp,
typename = _SafeConv<_Yp>>
1132 __shared_ptr(_Yp* __p)
1133 : _M_ptr(__p), _M_refcount(__p, typename is_array<_Tp>::type())
1135 static_assert( !is_void<_Yp>::value,
"incomplete type" );
1136 static_assert(
sizeof(_Yp) > 0,
"incomplete type" );
1137 _M_enable_shared_from_this_with(__p);
1140 template<
typename _Yp,
typename _Deleter,
typename = _SafeConv<_Yp>>
1141 __shared_ptr(_Yp* __p, _Deleter __d)
1142 : _M_ptr(__p), _M_refcount(__p,
std::
move(__d))
1144 static_assert(__is_invocable<_Deleter&, _Yp*&>::value,
1145 "deleter expression d(p) is well-formed");
1146 _M_enable_shared_from_this_with(__p);
1149 template<
typename _Yp,
typename _Deleter,
typename _Alloc,
1150 typename = _SafeConv<_Yp>>
1151 __shared_ptr(_Yp* __p, _Deleter __d, _Alloc __a)
1154 static_assert(__is_invocable<_Deleter&, _Yp*&>::value,
1155 "deleter expression d(p) is well-formed");
1156 _M_enable_shared_from_this_with(__p);
1159 template<
typename _Deleter>
1160 __shared_ptr(nullptr_t __p, _Deleter __d)
1161 : _M_ptr(0), _M_refcount(__p,
std::
move(__d))
1164 template<
typename _Deleter,
typename _Alloc>
1165 __shared_ptr(nullptr_t __p, _Deleter __d, _Alloc __a)
1170 template<
typename _Yp>
1171 __shared_ptr(
const __shared_ptr<_Yp, _Lp>& __r,
1172 element_type* __p) noexcept
1173 : _M_ptr(__p), _M_refcount(__r._M_refcount)
1177 template<
typename _Yp>
1178 __shared_ptr(__shared_ptr<_Yp, _Lp>&& __r,
1179 element_type* __p) noexcept
1180 : _M_ptr(__p), _M_refcount()
1182 _M_refcount._M_swap(__r._M_refcount);
1186 __shared_ptr(
const __shared_ptr&) noexcept =
default;
1187 __shared_ptr& operator=(
const __shared_ptr&) noexcept =
default;
1188 ~__shared_ptr() =
default;
1190 template<
typename _Yp,
typename = _Compatible<_Yp>>
1191 __shared_ptr(
const __shared_ptr<_Yp, _Lp>& __r) noexcept
1192 : _M_ptr(__r._M_ptr), _M_refcount(__r._M_refcount)
1195 __shared_ptr(__shared_ptr&& __r) noexcept
1196 : _M_ptr(__r._M_ptr), _M_refcount()
1198 _M_refcount._M_swap(__r._M_refcount);
1202 template<
typename _Yp,
typename = _Compatible<_Yp>>
1203 __shared_ptr(__shared_ptr<_Yp, _Lp>&& __r) noexcept
1204 : _M_ptr(__r._M_ptr), _M_refcount()
1206 _M_refcount._M_swap(__r._M_refcount);
1210 template<
typename _Yp,
typename = _Compatible<_Yp>>
1211 explicit __shared_ptr(
const __weak_ptr<_Yp, _Lp>& __r)
1212 : _M_refcount(__r._M_refcount)
1216 _M_ptr = __r._M_ptr;
1220 template<
typename _Yp,
typename _Del,
1221 typename = _UniqCompatible<_Yp, _Del>>
1222 __shared_ptr(unique_ptr<_Yp, _Del>&& __r)
1223 : _M_ptr(__r.get()), _M_refcount()
1225 auto __raw = __to_address(__r.get());
1226 _M_refcount = __shared_count<_Lp>(
std::move(__r));
1227 _M_enable_shared_from_this_with(__raw);
1230 #if __cplusplus <= 201402L && _GLIBCXX_USE_DEPRECATED
1233 template<
typename _Tp1,
typename _Del,
1234 typename enable_if<__and_<
1235 __not_<is_array<_Tp>>, is_array<_Tp1>,
1236 is_convertible<typename unique_ptr<_Tp1, _Del>::pointer, _Tp*>
1237 >::value,
bool>::type =
true>
1238 __shared_ptr(unique_ptr<_Tp1, _Del>&& __r, __sp_array_delete)
1239 : _M_ptr(__r.get()), _M_refcount()
1241 auto __raw = __to_address(__r.get());
1242 _M_refcount = __shared_count<_Lp>(
std::move(__r));
1243 _M_enable_shared_from_this_with(__raw);
1248 #if _GLIBCXX_USE_DEPRECATED
1249 #pragma GCC diagnostic push
1250 #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
1252 template<
typename _Yp,
typename = _Compatible<_Yp>>
1253 __shared_ptr(auto_ptr<_Yp>&& __r);
1254 #pragma GCC diagnostic pop
1257 constexpr __shared_ptr(nullptr_t) noexcept : __shared_ptr() { }
1259 template<
typename _Yp>
1261 operator=(
const __shared_ptr<_Yp, _Lp>& __r) noexcept
1263 _M_ptr = __r._M_ptr;
1264 _M_refcount = __r._M_refcount;
1268 #if _GLIBCXX_USE_DEPRECATED
1269 #pragma GCC diagnostic push
1270 #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
1271 template<
typename _Yp>
1273 operator=(auto_ptr<_Yp>&& __r)
1275 __shared_ptr(
std::move(__r)).swap(*
this);
1278 #pragma GCC diagnostic pop
1282 operator=(__shared_ptr&& __r) noexcept
1284 __shared_ptr(
std::move(__r)).swap(*
this);
1290 operator=(__shared_ptr<_Yp, _Lp>&& __r) noexcept
1292 __shared_ptr(
std::move(__r)).swap(*
this);
1296 template<
typename _Yp,
typename _Del>
1297 _UniqAssignable<_Yp, _Del>
1298 operator=(unique_ptr<_Yp, _Del>&& __r)
1300 __shared_ptr(
std::move(__r)).swap(*
this);
1306 { __shared_ptr().swap(*
this); }
1308 template<
typename _Yp>
1313 __glibcxx_assert(__p == 0 || __p != _M_ptr);
1314 __shared_ptr(__p).swap(*
this);
1317 template<
typename _Yp,
typename _Deleter>
1319 reset(_Yp* __p, _Deleter __d)
1320 { __shared_ptr(__p,
std::move(__d)).swap(*
this); }
1322 template<
typename _Yp,
typename _Deleter,
typename _Alloc>
1324 reset(_Yp* __p, _Deleter __d, _Alloc __a)
1329 get() const noexcept
1333 explicit operator bool() const
1334 {
return _M_ptr == 0 ? false :
true; }
1338 unique() const noexcept
1339 {
return _M_refcount._M_unique(); }
1343 use_count() const noexcept
1344 {
return _M_refcount._M_get_use_count(); }
1348 swap(__shared_ptr<_Tp, _Lp>& __other) noexcept
1350 std::swap(_M_ptr, __other._M_ptr);
1351 _M_refcount._M_swap(__other._M_refcount);
1361 template<
typename _Tp1>
1363 owner_before(__shared_ptr<_Tp1, _Lp>
const& __rhs)
const noexcept
1364 {
return _M_refcount._M_less(__rhs._M_refcount); }
1366 template<
typename _Tp1>
1368 owner_before(__weak_ptr<_Tp1, _Lp>
const& __rhs)
const noexcept
1369 {
return _M_refcount._M_less(__rhs._M_refcount); }
1374 template<
typename _Alloc,
typename... _Args>
1375 __shared_ptr(_Sp_alloc_shared_tag<_Alloc> __tag, _Args&&... __args)
1376 : _M_ptr(), _M_refcount(_M_ptr, __tag,
std::
forward<_Args>(__args)...)
1377 { _M_enable_shared_from_this_with(_M_ptr); }
1379 template<
typename _Tp1, _Lock_policy _Lp1,
typename _Alloc,
1381 friend __shared_ptr<_Tp1, _Lp1>
1382 __allocate_shared(
const _Alloc& __a, _Args&&... __args);
1386 __shared_ptr(
const __weak_ptr<_Tp, _Lp>& __r, std::nothrow_t)
1387 : _M_refcount(__r._M_refcount,
std::nothrow)
1389 _M_ptr = _M_refcount._M_get_use_count() ? __r._M_ptr :
nullptr;
1392 friend class __weak_ptr<_Tp, _Lp>;
1396 template<
typename _Yp>
1397 using __esft_base_t = decltype(__enable_shared_from_this_base(
1398 std::declval<
const __shared_count<_Lp>&>(),
1399 std::declval<_Yp*>()));
1402 template<
typename _Yp,
typename =
void>
1403 struct __has_esft_base
1406 template<
typename _Yp>
1407 struct __has_esft_base<_Yp, __void_t<__esft_base_t<_Yp>>>
1408 : __not_<is_array<_Tp>> { };
1410 template<typename _Yp, typename _Yp2 = typename remove_cv<_Yp>::type>
1411 typename enable_if<__has_esft_base<_Yp2>::value>::type
1412 _M_enable_shared_from_this_with(_Yp* __p) noexcept
1414 if (
auto __base = __enable_shared_from_this_base(_M_refcount, __p))
1415 __base->_M_weak_assign(
const_cast<_Yp2*
>(__p), _M_refcount);
1418 template<typename _Yp, typename _Yp2 = typename remove_cv<_Yp>::type>
1419 typename enable_if<!__has_esft_base<_Yp2>::value>::type
1420 _M_enable_shared_from_this_with(_Yp*) noexcept
1425 {
return _M_refcount._M_get_deleter(__ti); }
1427 template<
typename _Tp1, _Lock_policy _Lp1>
friend class __shared_ptr;
1428 template<
typename _Tp1, _Lock_policy _Lp1>
friend class __weak_ptr;
1430 template<
typename _Del,
typename _Tp1, _Lock_policy _Lp1>
1431 friend _Del* get_deleter(
const __shared_ptr<_Tp1, _Lp1>&) noexcept;
1433 template<
typename _Del,
typename _Tp1>
1434 friend _Del* get_deleter(
const shared_ptr<_Tp1>&) noexcept;
1436 element_type* _M_ptr;
1437 __shared_count<_Lp> _M_refcount;
1442 template<
typename _Tp1,
typename _Tp2, _Lock_policy _Lp>
1444 operator==(
const __shared_ptr<_Tp1, _Lp>& __a,
1445 const __shared_ptr<_Tp2, _Lp>& __b) noexcept
1446 {
return __a.get() == __b.get(); }
1448 template<
typename _Tp, _Lock_policy _Lp>
1450 operator==(
const __shared_ptr<_Tp, _Lp>& __a, nullptr_t) noexcept
1453 #ifdef __cpp_lib_three_way_comparison
1454 template<
typename _Tp,
typename _Up, _Lock_policy _Lp>
1455 inline strong_ordering
1456 operator<=>(
const __shared_ptr<_Tp, _Lp>& __a,
1457 const __shared_ptr<_Up, _Lp>& __b) noexcept
1458 {
return compare_three_way()(__a.get(), __b.get()); }
1460 template<
typename _Tp, _Lock_policy _Lp>
1461 inline strong_ordering
1462 operator<=>(
const __shared_ptr<_Tp, _Lp>& __a, nullptr_t) noexcept
1464 using pointer =
typename __shared_ptr<_Tp, _Lp>::element_type*;
1465 return compare_three_way()(__a.get(),
static_cast<pointer
>(
nullptr));
1468 template<
typename _Tp, _Lock_policy _Lp>
1470 operator==(nullptr_t,
const __shared_ptr<_Tp, _Lp>& __a) noexcept
1473 template<
typename _Tp1,
typename _Tp2, _Lock_policy _Lp>
1475 operator!=(
const __shared_ptr<_Tp1, _Lp>& __a,
1476 const __shared_ptr<_Tp2, _Lp>& __b) noexcept
1477 {
return __a.get() != __b.get(); }
1479 template<
typename _Tp, _Lock_policy _Lp>
1481 operator!=(
const __shared_ptr<_Tp, _Lp>& __a, nullptr_t) noexcept
1482 {
return (
bool)__a; }
1484 template<
typename _Tp, _Lock_policy _Lp>
1486 operator!=(nullptr_t,
const __shared_ptr<_Tp, _Lp>& __a) noexcept
1487 {
return (
bool)__a; }
1489 template<
typename _Tp,
typename _Up, _Lock_policy _Lp>
1491 operator<(
const __shared_ptr<_Tp, _Lp>& __a,
1492 const __shared_ptr<_Up, _Lp>& __b) noexcept
1494 using _Tp_elt =
typename __shared_ptr<_Tp, _Lp>::element_type;
1495 using _Up_elt =
typename __shared_ptr<_Up, _Lp>::element_type;
1496 using _Vp =
typename common_type<_Tp_elt*, _Up_elt*>::type;
1497 return less<_Vp>()(__a.get(), __b.get());
1500 template<
typename _Tp, _Lock_policy _Lp>
1502 operator<(
const __shared_ptr<_Tp, _Lp>& __a, nullptr_t) noexcept
1504 using _Tp_elt =
typename __shared_ptr<_Tp, _Lp>::element_type;
1505 return less<_Tp_elt*>()(__a.get(),
nullptr);
1508 template<
typename _Tp, _Lock_policy _Lp>
1510 operator<(nullptr_t,
const __shared_ptr<_Tp, _Lp>& __a) noexcept
1512 using _Tp_elt =
typename __shared_ptr<_Tp, _Lp>::element_type;
1513 return less<_Tp_elt*>()(
nullptr, __a.get());
1516 template<
typename _Tp1,
typename _Tp2, _Lock_policy _Lp>
1518 operator<=(
const __shared_ptr<_Tp1, _Lp>& __a,
1519 const __shared_ptr<_Tp2, _Lp>& __b) noexcept
1520 {
return !(__b < __a); }
1522 template<
typename _Tp, _Lock_policy _Lp>
1524 operator<=(
const __shared_ptr<_Tp, _Lp>& __a, nullptr_t) noexcept
1525 {
return !(
nullptr < __a); }
1527 template<
typename _Tp, _Lock_policy _Lp>
1529 operator<=(nullptr_t,
const __shared_ptr<_Tp, _Lp>& __a) noexcept
1530 {
return !(__a <
nullptr); }
1532 template<
typename _Tp1,
typename _Tp2, _Lock_policy _Lp>
1534 operator>(
const __shared_ptr<_Tp1, _Lp>& __a,
1535 const __shared_ptr<_Tp2, _Lp>& __b) noexcept
1536 {
return (__b < __a); }
1538 template<
typename _Tp, _Lock_policy _Lp>
1540 operator>(
const __shared_ptr<_Tp, _Lp>& __a, nullptr_t) noexcept
1541 {
return nullptr < __a; }
1543 template<
typename _Tp, _Lock_policy _Lp>
1545 operator>(nullptr_t,
const __shared_ptr<_Tp, _Lp>& __a) noexcept
1546 {
return __a <
nullptr; }
1548 template<
typename _Tp1,
typename _Tp2, _Lock_policy _Lp>
1550 operator>=(
const __shared_ptr<_Tp1, _Lp>& __a,
1551 const __shared_ptr<_Tp2, _Lp>& __b) noexcept
1552 {
return !(__a < __b); }
1554 template<
typename _Tp, _Lock_policy _Lp>
1556 operator>=(
const __shared_ptr<_Tp, _Lp>& __a, nullptr_t) noexcept
1557 {
return !(__a <
nullptr); }
1559 template<
typename _Tp, _Lock_policy _Lp>
1561 operator>=(nullptr_t,
const __shared_ptr<_Tp, _Lp>& __a) noexcept
1562 {
return !(
nullptr < __a); }
1566 template<
typename _Tp, _Lock_policy _Lp>
1568 swap(__shared_ptr<_Tp, _Lp>& __a, __shared_ptr<_Tp, _Lp>& __b) noexcept
1578 template<
typename _Tp,
typename _Tp1, _Lock_policy _Lp>
1579 inline __shared_ptr<_Tp, _Lp>
1582 using _Sp = __shared_ptr<_Tp, _Lp>;
1583 return _Sp(__r,
static_cast<typename _Sp::element_type*
>(__r.get()));
1591 template<
typename _Tp,
typename _Tp1, _Lock_policy _Lp>
1592 inline __shared_ptr<_Tp, _Lp>
1595 using _Sp = __shared_ptr<_Tp, _Lp>;
1596 return _Sp(__r,
const_cast<typename _Sp::element_type*
>(__r.get()));
1604 template<
typename _Tp,
typename _Tp1, _Lock_policy _Lp>
1605 inline __shared_ptr<_Tp, _Lp>
1608 using _Sp = __shared_ptr<_Tp, _Lp>;
1609 if (
auto* __p =
dynamic_cast<typename _Sp::element_type*
>(__r.get()))
1610 return _Sp(__r, __p);
1614 #if __cplusplus > 201402L
1615 template<
typename _Tp,
typename _Tp1, _Lock_policy _Lp>
1616 inline __shared_ptr<_Tp, _Lp>
1617 reinterpret_pointer_cast(
const __shared_ptr<_Tp1, _Lp>& __r) noexcept
1619 using _Sp = __shared_ptr<_Tp, _Lp>;
1620 return _Sp(__r,
reinterpret_cast<typename _Sp::element_type*
>(__r.get()));
1624 template<
typename _Tp, _Lock_policy _Lp>
1627 template<
typename _Yp,
typename _Res =
void>
1628 using _Compatible =
typename
1629 enable_if<__sp_compatible_with<_Yp*, _Tp*>::value, _Res>::type;
1632 template<
typename _Yp>
1633 using _Assignable = _Compatible<_Yp, __weak_ptr&>;
1636 using element_type =
typename remove_extent<_Tp>::type;
1638 constexpr __weak_ptr() noexcept
1639 : _M_ptr(
nullptr), _M_refcount()
1642 __weak_ptr(
const __weak_ptr&) noexcept =
default;
1644 ~__weak_ptr() =
default;
1660 template<
typename _Yp,
typename = _Compatible<_Yp>>
1661 __weak_ptr(
const __weak_ptr<_Yp, _Lp>& __r) noexcept
1662 : _M_refcount(__r._M_refcount)
1663 { _M_ptr = __r.lock().get(); }
1665 template<
typename _Yp,
typename = _Compatible<_Yp>>
1666 __weak_ptr(
const __shared_ptr<_Yp, _Lp>& __r) noexcept
1667 : _M_ptr(__r._M_ptr), _M_refcount(__r._M_refcount)
1670 __weak_ptr(__weak_ptr&& __r) noexcept
1671 : _M_ptr(__r._M_ptr), _M_refcount(
std::move(__r._M_refcount))
1672 { __r._M_ptr =
nullptr; }
1674 template<
typename _Yp,
typename = _Compatible<_Yp>>
1675 __weak_ptr(__weak_ptr<_Yp, _Lp>&& __r) noexcept
1676 : _M_ptr(__r.lock().get()), _M_refcount(
std::move(__r._M_refcount))
1677 { __r._M_ptr =
nullptr; }
1680 operator=(
const __weak_ptr& __r) noexcept =
default;
1682 template<
typename _Yp>
1684 operator=(
const __weak_ptr<_Yp, _Lp>& __r) noexcept
1686 _M_ptr = __r.lock().get();
1687 _M_refcount = __r._M_refcount;
1691 template<
typename _Yp>
1693 operator=(
const __shared_ptr<_Yp, _Lp>& __r) noexcept
1695 _M_ptr = __r._M_ptr;
1696 _M_refcount = __r._M_refcount;
1701 operator=(__weak_ptr&& __r) noexcept
1703 _M_ptr = __r._M_ptr;
1704 _M_refcount =
std::move(__r._M_refcount);
1705 __r._M_ptr =
nullptr;
1709 template<
typename _Yp>
1711 operator=(__weak_ptr<_Yp, _Lp>&& __r) noexcept
1713 _M_ptr = __r.lock().get();
1714 _M_refcount =
std::move(__r._M_refcount);
1715 __r._M_ptr =
nullptr;
1719 __shared_ptr<_Tp, _Lp>
1720 lock() const noexcept
1721 {
return __shared_ptr<element_type, _Lp>(*
this, std::nothrow); }
1724 use_count() const noexcept
1725 {
return _M_refcount._M_get_use_count(); }
1728 expired() const noexcept
1729 {
return _M_refcount._M_get_use_count() == 0; }
1731 template<
typename _Tp1>
1733 owner_before(
const __shared_ptr<_Tp1, _Lp>& __rhs)
const noexcept
1734 {
return _M_refcount._M_less(__rhs._M_refcount); }
1736 template<
typename _Tp1>
1738 owner_before(
const __weak_ptr<_Tp1, _Lp>& __rhs)
const noexcept
1739 {
return _M_refcount._M_less(__rhs._M_refcount); }
1743 { __weak_ptr().swap(*
this); }
1746 swap(__weak_ptr& __s) noexcept
1748 std::swap(_M_ptr, __s._M_ptr);
1749 _M_refcount._M_swap(__s._M_refcount);
1755 _M_assign(_Tp* __ptr,
const __shared_count<_Lp>& __refcount) noexcept
1757 if (use_count() == 0)
1760 _M_refcount = __refcount;
1764 template<
typename _Tp1, _Lock_policy _Lp1>
friend class __shared_ptr;
1765 template<
typename _Tp1, _Lock_policy _Lp1>
friend class __weak_ptr;
1766 friend class __enable_shared_from_this<_Tp, _Lp>;
1767 friend class enable_shared_from_this<_Tp>;
1769 element_type* _M_ptr;
1770 __weak_count<_Lp> _M_refcount;
1774 template<
typename _Tp, _Lock_policy _Lp>
1776 swap(__weak_ptr<_Tp, _Lp>& __a, __weak_ptr<_Tp, _Lp>& __b) noexcept
1779 template<
typename _Tp,
typename _Tp1>
1780 struct _Sp_owner_less :
public binary_function<_Tp, _Tp, bool>
1783 operator()(
const _Tp& __lhs,
const _Tp& __rhs)
const noexcept
1784 {
return __lhs.owner_before(__rhs); }
1787 operator()(
const _Tp& __lhs,
const _Tp1& __rhs)
const noexcept
1788 {
return __lhs.owner_before(__rhs); }
1791 operator()(
const _Tp1& __lhs,
const _Tp& __rhs)
const noexcept
1792 {
return __lhs.owner_before(__rhs); }
1796 struct _Sp_owner_less<void, void>
1798 template<
typename _Tp,
typename _Up>
1800 operator()(
const _Tp& __lhs,
const _Up& __rhs)
const noexcept
1801 -> decltype(__lhs.owner_before(__rhs))
1802 {
return __lhs.owner_before(__rhs); }
1804 using is_transparent = void;
1807 template<
typename _Tp, _Lock_policy _Lp>
1808 struct owner_less<__shared_ptr<_Tp, _Lp>>
1809 :
public _Sp_owner_less<__shared_ptr<_Tp, _Lp>, __weak_ptr<_Tp, _Lp>>
1812 template<
typename _Tp, _Lock_policy _Lp>
1813 struct owner_less<__weak_ptr<_Tp, _Lp>>
1814 :
public _Sp_owner_less<__weak_ptr<_Tp, _Lp>, __shared_ptr<_Tp, _Lp>>
1818 template<
typename _Tp, _Lock_policy _Lp>
1819 class __enable_shared_from_this
1822 constexpr __enable_shared_from_this() noexcept { }
1824 __enable_shared_from_this(
const __enable_shared_from_this&) noexcept { }
1826 __enable_shared_from_this&
1827 operator=(
const __enable_shared_from_this&) noexcept
1830 ~__enable_shared_from_this() { }
1833 __shared_ptr<_Tp, _Lp>
1835 {
return __shared_ptr<_Tp, _Lp>(this->_M_weak_this); }
1837 __shared_ptr<const _Tp, _Lp>
1838 shared_from_this()
const
1839 {
return __shared_ptr<const _Tp, _Lp>(this->_M_weak_this); }
1841 #if __cplusplus > 201402L || !defined(__STRICT_ANSI__)
1842 __weak_ptr<_Tp, _Lp>
1843 weak_from_this() noexcept
1844 {
return this->_M_weak_this; }
1846 __weak_ptr<const _Tp, _Lp>
1847 weak_from_this() const noexcept
1848 {
return this->_M_weak_this; }
1852 template<
typename _Tp1>
1854 _M_weak_assign(_Tp1* __p,
const __shared_count<_Lp>& __n)
const noexcept
1855 { _M_weak_this._M_assign(__p, __n); }
1857 friend const __enable_shared_from_this*
1858 __enable_shared_from_this_base(
const __shared_count<_Lp>&,
1859 const __enable_shared_from_this* __p)
1862 template<
typename, _Lock_policy>
1863 friend class __shared_ptr;
1865 mutable __weak_ptr<_Tp, _Lp> _M_weak_this;
1868 template<
typename _Tp, _Lock_policy _Lp = __default_lock_policy,
1869 typename _Alloc,
typename... _Args>
1870 inline __shared_ptr<_Tp, _Lp>
1871 __allocate_shared(
const _Alloc& __a, _Args&&... __args)
1873 static_assert(!is_array<_Tp>::value,
"make_shared<T[]> not supported");
1875 return __shared_ptr<_Tp, _Lp>(_Sp_alloc_shared_tag<_Alloc>{__a},
1876 std::forward<_Args>(__args)...);
1879 template<
typename _Tp, _Lock_policy _Lp = __default_lock_policy,
1881 inline __shared_ptr<_Tp, _Lp>
1882 __make_shared(_Args&&... __args)
1884 typedef typename std::remove_const<_Tp>::type _Tp_nc;
1886 std::forward<_Args>(__args)...);
1890 template<
typename _Tp, _Lock_policy _Lp>
1891 struct hash<__shared_ptr<_Tp, _Lp>>
1892 :
public __hash_base<size_t, __shared_ptr<_Tp, _Lp>>
1895 operator()(
const __shared_ptr<_Tp, _Lp>& __s)
const noexcept
1902 _GLIBCXX_END_NAMESPACE_VERSION
constexpr complex< _Tp > operator*(const complex< _Tp > &__x, const complex< _Tp > &__y)
Return new complex value x times y.
integral_constant< bool, true > true_type
The type used as a compile-time boolean with true value.
integral_constant< bool, false > false_type
The type used as a compile-time boolean with false value.
constexpr _Tp * __addressof(_Tp &__r) noexcept
Same as C++11 std::addressof.
constexpr std::remove_reference< _Tp >::type && move(_Tp &&__t) noexcept
Convert a value to an rvalue.
constexpr _Tp && forward(typename std::remove_reference< _Tp >::type &__t) noexcept
Forward an lvalue.
void lock(_L1 &__l1, _L2 &__l2, _L3 &... __l3)
Generic lock.
ISO C++ entities toplevel namespace is std.
__allocated_ptr< _Alloc > __allocate_guarded(_Alloc &__a)
Allocate space for a single object using __a.
__shared_ptr< _Tp, _Lp > static_pointer_cast(const __shared_ptr< _Tp1, _Lp > &__r) noexcept
static_pointer_cast
__shared_ptr< _Tp, _Lp > const_pointer_cast(const __shared_ptr< _Tp1, _Lp > &__r) noexcept
const_pointer_cast
__shared_ptr< _Tp, _Lp > dynamic_pointer_cast(const __shared_ptr< _Tp1, _Lp > &__r) noexcept
dynamic_pointer_cast
constexpr _Iterator __base(_Iterator __it)
Primary class template hash.
static constexpr auto construct(_Alloc &__a, _Tp *__p, _Args &&... __args) noexcept(noexcept(_S_construct(__a, __p, std::forward< _Args >(__args)...))) -> decltype(_S_construct(__a, __p, std::forward< _Args >(__args)...))
Construct an object of type _Tp
static constexpr void destroy(_Alloc &__a, _Tp *__p) noexcept(noexcept(_S_destroy(__a, __p, 0)))
Destroy an object of type _Tp.
The standard allocator, as per C++03 [20.4.1].
Base class for all library exceptions.
Exception possibly thrown by shared_ptr.
virtual char const * what() const noexcept
One of the comparison functors.
20.7.1.2 unique_ptr for single objects.
A simple smart pointer providing strict ownership semantics.