50 #define _SHARED_PTR_H 1
55 namespace std _GLIBCXX_VISIBILITY(default)
57 _GLIBCXX_BEGIN_NAMESPACE_VERSION
68 template<
typename _Ch,
typename _Tr,
typename _Tp, _Lock_policy _Lp>
71 const __shared_ptr<_Tp, _Lp>& __p)
77 template<
typename _Del,
typename _Tp, _Lock_policy _Lp>
79 get_deleter(
const __shared_ptr<_Tp, _Lp>& __p) noexcept
82 return static_cast<_Del*
>(__p._M_get_deleter(
typeid(_Del)));
92 template<
typename _Del,
typename _Tp>
97 return static_cast<_Del*
>(__p._M_get_deleter(
typeid(_Del)));
121 template<
typename _Tp>
124 template<
typename... _Args>
125 using _Constructible =
typename enable_if<
129 template<
typename _Arg>
137 using element_type =
typename __shared_ptr<_Tp>::element_type;
139 #if __cplusplus >= 201703L
140 # define __cpp_lib_shared_ptr_weak_type 201606
158 template<
typename _Yp,
typename = _Constructible<_Yp*>>
175 template<
typename _Yp,
typename _Deleter,
176 typename = _Constructible<_Yp*, _Deleter>>
178 : __shared_ptr<_Tp>(__p,
std::
move(__d)) { }
193 template<
typename _Deleter>
195 : __shared_ptr<_Tp>(__p,
std::
move(__d)) { }
212 template<
typename _Yp,
typename _Deleter,
typename _Alloc,
213 typename = _Constructible<_Yp*, _Deleter, _Alloc>>
232 template<
typename _Deleter,
typename _Alloc>
256 template<
typename _Yp>
258 : __shared_ptr<_Tp>(__r, __p) { }
260 #if __cplusplus > 201703L
283 template<
typename _Yp>
285 : __shared_ptr<_Tp>(
std::move(__r), __p) { }
294 template<
typename _Yp,
295 typename = _Constructible<const shared_ptr<_Yp>&>>
297 : __shared_ptr<_Tp>(__r) { }
312 template<
typename _Yp,
typename = _Constructible<shared_ptr<_Yp>>>
324 template<
typename _Yp,
typename = _Constructible<const weak_ptr<_Yp>&>>
326 : __shared_ptr<_Tp>(__r) { }
328 #if _GLIBCXX_USE_DEPRECATED
329 #pragma GCC diagnostic push
330 #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
331 template<
typename _Yp,
typename = _Constructible<auto_ptr<_Yp>>>
333 #pragma GCC diagnostic pop
338 template<
typename _Yp,
typename _Del,
339 typename = _Constructible<unique_ptr<_Yp, _Del>>>
341 : __shared_ptr<_Tp>(
std::
move(__r)) { }
343 #if __cplusplus <= 201402L && _GLIBCXX_USE_DEPRECATED
347 template<
typename _Yp,
typename _Del,
348 _Constructible<unique_ptr<_Yp, _Del>, __sp_array_delete>* = 0>
350 : __shared_ptr<_Tp>(
std::
move(__r), __sp_array_delete()) { }
361 template<
typename _Yp>
362 _Assignable<const shared_ptr<_Yp>&>
365 this->__shared_ptr<_Tp>::operator=(__r);
369 #if _GLIBCXX_USE_DEPRECATED
370 #pragma GCC diagnostic push
371 #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
372 template<
typename _Yp>
373 _Assignable<auto_ptr<_Yp>>
374 operator=(auto_ptr<_Yp>&& __r)
376 this->__shared_ptr<_Tp>::operator=(
std::move(__r));
379 #pragma GCC diagnostic pop
385 this->__shared_ptr<_Tp>::operator=(
std::move(__r));
390 _Assignable<shared_ptr<_Yp>>
391 operator=(shared_ptr<_Yp>&& __r) noexcept
393 this->__shared_ptr<_Tp>::operator=(
std::move(__r));
397 template<
typename _Yp,
typename _Del>
398 _Assignable<unique_ptr<_Yp, _Del>>
399 operator=(unique_ptr<_Yp, _Del>&& __r)
401 this->__shared_ptr<_Tp>::operator=(
std::move(__r));
407 template<
typename _Alloc,
typename... _Args>
408 shared_ptr(_Sp_alloc_shared_tag<_Alloc> __tag, _Args&&... __args)
409 : __shared_ptr<_Tp>(__tag,
std::
forward<_Args>(__args)...)
412 template<
typename _Yp,
typename _Alloc,
typename... _Args>
413 friend shared_ptr<_Yp>
414 allocate_shared(
const _Alloc& __a, _Args&&... __args);
417 shared_ptr(
const weak_ptr<_Tp>& __r, std::nothrow_t) noexcept
418 : __shared_ptr<_Tp>(__r, std::nothrow) { }
420 friend class weak_ptr<_Tp>;
423 #if __cpp_deduction_guides >= 201606
424 template<
typename _Tp>
425 shared_ptr(weak_ptr<_Tp>) -> shared_ptr<_Tp>;
426 template<
typename _Tp,
typename _Del>
427 shared_ptr(unique_ptr<_Tp, _Del>) -> shared_ptr<_Tp>;
435 template<
typename _Tp,
typename _Up>
436 _GLIBCXX_NODISCARD
inline bool
438 {
return __a.get() == __b.get(); }
441 template<
typename _Tp>
442 _GLIBCXX_NODISCARD
inline bool
446 #ifdef __cpp_lib_three_way_comparison
447 template<
typename _Tp,
typename _Up>
448 inline strong_ordering
451 {
return compare_three_way()(__a.get(), __b.get()); }
453 template<
typename _Tp>
454 inline strong_ordering
455 operator<=>(
const shared_ptr<_Tp>& __a, nullptr_t) noexcept
458 return compare_three_way()(__a.get(),
static_cast<pointer
>(
nullptr));
462 template<
typename _Tp>
463 _GLIBCXX_NODISCARD
inline bool
468 template<
typename _Tp,
typename _Up>
469 _GLIBCXX_NODISCARD
inline bool
471 {
return __a.get() != __b.get(); }
474 template<
typename _Tp>
475 _GLIBCXX_NODISCARD
inline bool
477 {
return (
bool)__a; }
480 template<
typename _Tp>
481 _GLIBCXX_NODISCARD
inline bool
483 {
return (
bool)__a; }
486 template<
typename _Tp,
typename _Up>
487 _GLIBCXX_NODISCARD
inline bool
493 return less<_Vp>()(__a.get(), __b.get());
497 template<
typename _Tp>
498 _GLIBCXX_NODISCARD
inline bool
506 template<
typename _Tp>
507 _GLIBCXX_NODISCARD
inline bool
515 template<
typename _Tp,
typename _Up>
516 _GLIBCXX_NODISCARD
inline bool
518 {
return !(__b < __a); }
521 template<
typename _Tp>
522 _GLIBCXX_NODISCARD
inline bool
524 {
return !(
nullptr < __a); }
527 template<
typename _Tp>
528 _GLIBCXX_NODISCARD
inline bool
530 {
return !(__a <
nullptr); }
533 template<
typename _Tp,
typename _Up>
534 _GLIBCXX_NODISCARD
inline bool
536 {
return (__b < __a); }
539 template<
typename _Tp>
540 _GLIBCXX_NODISCARD
inline bool
542 {
return nullptr < __a; }
545 template<
typename _Tp>
546 _GLIBCXX_NODISCARD
inline bool
548 {
return __a <
nullptr; }
551 template<
typename _Tp,
typename _Up>
552 _GLIBCXX_NODISCARD
inline bool
554 {
return !(__a < __b); }
557 template<
typename _Tp>
558 _GLIBCXX_NODISCARD
inline bool
560 {
return !(__a <
nullptr); }
563 template<
typename _Tp>
564 _GLIBCXX_NODISCARD
inline bool
566 {
return !(
nullptr < __a); }
572 template<
typename _Tp>
580 template<
typename _Tp,
typename _Up>
585 return _Sp(__r,
static_cast<typename _Sp::element_type*
>(__r.get()));
589 template<
typename _Tp,
typename _Up>
594 return _Sp(__r,
const_cast<typename _Sp::element_type*
>(__r.get()));
598 template<
typename _Tp,
typename _Up>
603 if (
auto* __p =
dynamic_cast<typename _Sp::element_type*
>(__r.get()))
604 return _Sp(__r, __p);
608 #if __cplusplus >= 201703L
610 template<
typename _Tp,
typename _Up>
615 return _Sp(__r,
reinterpret_cast<typename _Sp::element_type*
>(__r.get()));
618 #if __cplusplus > 201703L
623 template<
typename _Tp,
typename _Up>
629 static_cast<typename _Sp::element_type*
>(__r.get()));
633 template<
typename _Tp,
typename _Up>
634 inline shared_ptr<_Tp>
637 using _Sp = shared_ptr<_Tp>;
639 const_cast<typename _Sp::element_type*
>(__r.get()));
643 template<
typename _Tp,
typename _Up>
644 inline shared_ptr<_Tp>
647 using _Sp = shared_ptr<_Tp>;
648 if (
auto* __p =
dynamic_cast<typename _Sp::element_type*
>(__r.get()))
654 template<
typename _Tp,
typename _Up>
655 inline shared_ptr<_Tp>
656 reinterpret_pointer_cast(shared_ptr<_Up>&& __r) noexcept
658 using _Sp = shared_ptr<_Tp>;
660 reinterpret_cast<typename _Sp::element_type*
>(__r.get()));
685 template<
typename _Tp>
688 template<
typename _Arg>
689 using _Constructible =
typename enable_if<
693 template<
typename _Arg>
699 constexpr
weak_ptr() noexcept =
default;
701 template<
typename _Yp,
702 typename = _Constructible<const shared_ptr<_Yp>&>>
704 : __weak_ptr<_Tp>(__r) { }
708 template<
typename _Yp,
typename = _Constructible<const weak_ptr<_Yp>&>>
710 : __weak_ptr<_Tp>(__r) { }
714 template<
typename _Yp,
typename = _Constructible<weak_ptr<_Yp>>>
719 operator=(
const weak_ptr& __r) noexcept =
default;
721 template<
typename _Yp>
722 _Assignable<const weak_ptr<_Yp>&>
725 this->__weak_ptr<_Tp>::operator=(__r);
729 template<
typename _Yp>
730 _Assignable<const shared_ptr<_Yp>&>
733 this->__weak_ptr<_Tp>::operator=(__r);
738 operator=(
weak_ptr&& __r) noexcept =
default;
740 template<
typename _Yp>
741 _Assignable<weak_ptr<_Yp>>
744 this->__weak_ptr<_Tp>::operator=(
std::move(__r));
749 lock()
const noexcept
753 #if __cpp_deduction_guides >= 201606
754 template<
typename _Tp>
761 template<
typename _Tp>
768 template<
typename _Tp =
void>
777 template<
typename _Tp>
779 :
public _Sp_owner_less<shared_ptr<_Tp>, weak_ptr<_Tp>>
783 template<
typename _Tp>
785 :
public _Sp_owner_less<weak_ptr<_Tp>, shared_ptr<_Tp>>
791 template<
typename _Tp>
811 shared_from_this()
const
814 #if __cplusplus > 201402L || !defined(__STRICT_ANSI__) // c++1z or gnu++11
815 #define __cpp_lib_enable_shared_from_this 201603
817 weak_from_this() noexcept
818 {
return this->_M_weak_this; }
821 weak_from_this()
const noexcept
822 {
return this->_M_weak_this; }
826 template<
typename _Tp1>
828 _M_weak_assign(_Tp1* __p,
const __shared_count<>& __n)
const noexcept
829 { _M_weak_this._M_assign(__p, __n); }
833 __enable_shared_from_this_base(
const __shared_count<>&,
837 template<
typename, _Lock_policy>
838 friend class __shared_ptr;
856 template<
typename _Tp,
typename _Alloc,
typename... _Args>
863 std::forward<_Args>(__args)...);
873 template<
typename _Tp,
typename... _Args>
877 typedef typename std::remove_cv<_Tp>::type _Tp_nc;
879 std::forward<_Args>(__args)...);
883 template<
typename _Tp>
885 :
public __hash_base<size_t, shared_ptr<_Tp>>
897 #if __cplusplus >= 201703L
898 namespace __detail::__variant
900 template<
typename>
struct _Never_valueless_alt;
904 template<
typename _Tp>
911 template<
typename _Tp>
912 struct _Never_valueless_alt<
std::weak_ptr<_Tp>>
918 _GLIBCXX_END_NAMESPACE_VERSION
921 #endif // _SHARED_PTR_H