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)));
123 template<
typename _Tp>
126 template<
typename... _Args>
127 using _Constructible =
typename enable_if<
131 template<
typename _Arg>
141 #if __cplusplus >= 201703L
142 # define __cpp_lib_shared_ptr_weak_type 201606
161 template<
typename _Yp,
typename = _Constructible<_Yp*>>
178 template<
typename _Yp,
typename _Deleter,
179 typename = _Constructible<_Yp*, _Deleter>>
181 : __shared_ptr<_Tp>(__p,
std::
move(__d)) { }
196 template<
typename _Deleter>
198 : __shared_ptr<_Tp>(__p,
std::
move(__d)) { }
215 template<
typename _Yp,
typename _Deleter,
typename _Alloc,
216 typename = _Constructible<_Yp*, _Deleter, _Alloc>>
235 template<
typename _Deleter,
typename _Alloc>
259 template<
typename _Yp>
261 : __shared_ptr<_Tp>(__r, __p) { }
263 #if __cplusplus > 201703L
287 template<
typename _Yp>
289 : __shared_ptr<_Tp>(
std::move(__r), __p) { }
298 template<
typename _Yp,
299 typename = _Constructible<const shared_ptr<_Yp>&>>
301 : __shared_ptr<_Tp>(__r) { }
316 template<
typename _Yp,
typename = _Constructible<shared_ptr<_Yp>>>
328 template<
typename _Yp,
typename = _Constructible<const weak_ptr<_Yp>&>>
330 : __shared_ptr<_Tp>(__r) { }
332 #if _GLIBCXX_USE_DEPRECATED
333 #pragma GCC diagnostic push
334 #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
335 template<
typename _Yp,
typename = _Constructible<auto_ptr<_Yp>>>
337 #pragma GCC diagnostic pop
342 template<
typename _Yp,
typename _Del,
343 typename = _Constructible<unique_ptr<_Yp, _Del>>>
345 : __shared_ptr<_Tp>(
std::
move(__r)) { }
347 #if __cplusplus <= 201402L && _GLIBCXX_USE_DEPRECATED
351 template<
typename _Yp,
typename _Del,
352 _Constructible<unique_ptr<_Yp, _Del>, __sp_array_delete>* = 0>
354 : __shared_ptr<_Tp>(
std::
move(__r), __sp_array_delete()) { }
365 template<
typename _Yp>
366 _Assignable<const shared_ptr<_Yp>&>
369 this->__shared_ptr<_Tp>::operator=(__r);
373 #if _GLIBCXX_USE_DEPRECATED
374 #pragma GCC diagnostic push
375 #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
376 template<
typename _Yp>
377 _Assignable<auto_ptr<_Yp>>
378 operator=(auto_ptr<_Yp>&& __r)
380 this->__shared_ptr<_Tp>::operator=(
std::move(__r));
383 #pragma GCC diagnostic pop
389 this->__shared_ptr<_Tp>::operator=(
std::move(__r));
394 _Assignable<shared_ptr<_Yp>>
395 operator=(shared_ptr<_Yp>&& __r) noexcept
397 this->__shared_ptr<_Tp>::operator=(
std::move(__r));
401 template<
typename _Yp,
typename _Del>
402 _Assignable<unique_ptr<_Yp, _Del>>
403 operator=(unique_ptr<_Yp, _Del>&& __r)
405 this->__shared_ptr<_Tp>::operator=(
std::move(__r));
411 template<
typename _Alloc,
typename... _Args>
412 shared_ptr(_Sp_alloc_shared_tag<_Alloc> __tag, _Args&&... __args)
413 : __shared_ptr<_Tp>(__tag,
std::
forward<_Args>(__args)...)
416 template<
typename _Yp,
typename _Alloc,
typename... _Args>
417 friend shared_ptr<_Yp>
418 allocate_shared(
const _Alloc& __a, _Args&&... __args);
421 shared_ptr(
const weak_ptr<_Tp>& __r, std::nothrow_t) noexcept
422 : __shared_ptr<_Tp>(__r, std::nothrow) { }
424 friend class weak_ptr<_Tp>;
427 #if __cpp_deduction_guides >= 201606
428 template<
typename _Tp>
429 shared_ptr(weak_ptr<_Tp>) -> shared_ptr<_Tp>;
430 template<
typename _Tp,
typename _Del>
431 shared_ptr(unique_ptr<_Tp, _Del>) -> shared_ptr<_Tp>;
439 template<
typename _Tp,
typename _Up>
440 _GLIBCXX_NODISCARD
inline bool
442 {
return __a.get() == __b.get(); }
445 template<
typename _Tp>
446 _GLIBCXX_NODISCARD
inline bool
450 #ifdef __cpp_lib_three_way_comparison
451 template<
typename _Tp,
typename _Up>
452 inline strong_ordering
455 {
return compare_three_way()(__a.get(), __b.get()); }
457 template<
typename _Tp>
458 inline strong_ordering
459 operator<=>(
const shared_ptr<_Tp>& __a, nullptr_t) noexcept
462 return compare_three_way()(__a.get(),
static_cast<pointer
>(
nullptr));
466 template<
typename _Tp>
467 _GLIBCXX_NODISCARD
inline bool
472 template<
typename _Tp,
typename _Up>
473 _GLIBCXX_NODISCARD
inline bool
475 {
return __a.get() != __b.get(); }
478 template<
typename _Tp>
479 _GLIBCXX_NODISCARD
inline bool
481 {
return (
bool)__a; }
484 template<
typename _Tp>
485 _GLIBCXX_NODISCARD
inline bool
487 {
return (
bool)__a; }
490 template<
typename _Tp,
typename _Up>
491 _GLIBCXX_NODISCARD
inline bool
497 return less<_Vp>()(__a.get(), __b.get());
501 template<
typename _Tp>
502 _GLIBCXX_NODISCARD
inline bool
510 template<
typename _Tp>
511 _GLIBCXX_NODISCARD
inline bool
519 template<
typename _Tp,
typename _Up>
520 _GLIBCXX_NODISCARD
inline bool
522 {
return !(__b < __a); }
525 template<
typename _Tp>
526 _GLIBCXX_NODISCARD
inline bool
528 {
return !(
nullptr < __a); }
531 template<
typename _Tp>
532 _GLIBCXX_NODISCARD
inline bool
534 {
return !(__a <
nullptr); }
537 template<
typename _Tp,
typename _Up>
538 _GLIBCXX_NODISCARD
inline bool
540 {
return (__b < __a); }
543 template<
typename _Tp>
544 _GLIBCXX_NODISCARD
inline bool
546 {
return nullptr < __a; }
549 template<
typename _Tp>
550 _GLIBCXX_NODISCARD
inline bool
552 {
return __a <
nullptr; }
555 template<
typename _Tp,
typename _Up>
556 _GLIBCXX_NODISCARD
inline bool
558 {
return !(__a < __b); }
561 template<
typename _Tp>
562 _GLIBCXX_NODISCARD
inline bool
564 {
return !(__a <
nullptr); }
567 template<
typename _Tp>
568 _GLIBCXX_NODISCARD
inline bool
570 {
return !(
nullptr < __a); }
576 template<
typename _Tp>
584 template<
typename _Tp,
typename _Up>
589 return _Sp(__r,
static_cast<typename _Sp::element_type*
>(__r.get()));
593 template<
typename _Tp,
typename _Up>
598 return _Sp(__r,
const_cast<typename _Sp::element_type*
>(__r.get()));
602 template<
typename _Tp,
typename _Up>
607 if (
auto* __p =
dynamic_cast<typename _Sp::element_type*
>(__r.get()))
608 return _Sp(__r, __p);
612 #if __cplusplus >= 201703L
615 template<
typename _Tp,
typename _Up>
620 return _Sp(__r,
reinterpret_cast<typename _Sp::element_type*
>(__r.get()));
623 #if __cplusplus > 201703L
629 template<
typename _Tp,
typename _Up>
635 static_cast<typename _Sp::element_type*
>(__r.get()));
640 template<
typename _Tp,
typename _Up>
646 const_cast<typename _Sp::element_type*
>(__r.get()));
651 template<
typename _Tp,
typename _Up>
656 if (
auto* __p =
dynamic_cast<typename _Sp::element_type*
>(__r.get()))
663 template<
typename _Tp,
typename _Up>
669 reinterpret_cast<typename _Sp::element_type*
>(__r.get()));
696 template<
typename _Tp>
699 template<
typename _Arg>
700 using _Constructible =
typename enable_if<
704 template<
typename _Arg>
710 constexpr
weak_ptr() noexcept =
default;
712 template<
typename _Yp,
713 typename = _Constructible<const shared_ptr<_Yp>&>>
715 : __weak_ptr<_Tp>(__r) { }
719 template<
typename _Yp,
typename = _Constructible<const weak_ptr<_Yp>&>>
721 : __weak_ptr<_Tp>(__r) { }
725 template<
typename _Yp,
typename = _Constructible<weak_ptr<_Yp>>>
730 operator=(
const weak_ptr& __r) noexcept =
default;
732 template<
typename _Yp>
733 _Assignable<const weak_ptr<_Yp>&>
736 this->__weak_ptr<_Tp>::operator=(__r);
740 template<
typename _Yp>
741 _Assignable<const shared_ptr<_Yp>&>
744 this->__weak_ptr<_Tp>::operator=(__r);
749 operator=(
weak_ptr&& __r) noexcept =
default;
751 template<
typename _Yp>
752 _Assignable<weak_ptr<_Yp>>
755 this->__weak_ptr<_Tp>::operator=(
std::move(__r));
760 lock()
const noexcept
764 #if __cpp_deduction_guides >= 201606
765 template<
typename _Tp>
772 template<
typename _Tp>
779 template<
typename _Tp =
void>
788 template<
typename _Tp>
790 :
public _Sp_owner_less<shared_ptr<_Tp>, weak_ptr<_Tp>>
794 template<
typename _Tp>
796 :
public _Sp_owner_less<weak_ptr<_Tp>, shared_ptr<_Tp>>
804 template<
typename _Tp>
824 shared_from_this()
const
827 #if __cplusplus > 201402L || !defined(__STRICT_ANSI__)
828 #define __cpp_lib_enable_shared_from_this 201603
835 {
return this->_M_weak_this; }
839 {
return this->_M_weak_this; }
844 template<
typename _Tp1>
846 _M_weak_assign(_Tp1* __p,
const __shared_count<>& __n)
const noexcept
847 { _M_weak_this._M_assign(__p, __n); }
850 friend const enable_shared_from_this*
851 __enable_shared_from_this_base(
const __shared_count<>&,
852 const enable_shared_from_this* __p)
855 template<
typename, _Lock_policy>
856 friend class __shared_ptr;
858 mutable weak_ptr<_Tp> _M_weak_this;
874 template<
typename _Tp,
typename _Alloc,
typename... _Args>
875 inline shared_ptr<_Tp>
881 std::forward<_Args>(__args)...);
891 template<
typename _Tp,
typename... _Args>
895 typedef typename std::remove_cv<_Tp>::type _Tp_nc;
897 std::forward<_Args>(__args)...);
901 template<
typename _Tp>
903 :
public __hash_base<size_t, shared_ptr<_Tp>>
915 #if __cplusplus >= 201703L
916 namespace __detail::__variant
918 template<
typename>
struct _Never_valueless_alt;
922 template<
typename _Tp>
929 template<
typename _Tp>
930 struct _Never_valueless_alt<
std::weak_ptr<_Tp>>
936 _GLIBCXX_END_NAMESPACE_VERSION
shared_ptr< _Tp > make_shared(_Args &&... __args)
Create an object that is owned by a shared_ptr.
bool operator!=(nullptr_t, const shared_ptr< _Tp > &__a) noexcept
shared_ptr comparison with nullptr
bool operator>(const shared_ptr< _Tp > &__a, nullptr_t) noexcept
shared_ptr comparison with nullptr
bool operator==(const shared_ptr< _Tp > &__a, nullptr_t) noexcept
shared_ptr comparison with nullptr
bool operator==(nullptr_t, const shared_ptr< _Tp > &__a) noexcept
shared_ptr comparison with nullptr
shared_ptr< _Tp > static_pointer_cast(const shared_ptr< _Up > &__r) noexcept
Convert type of shared_ptr, via static_cast
bool operator!=(const shared_ptr< _Tp > &__a, const shared_ptr< _Up > &__b) noexcept
Inequality operator for shared_ptr objects, compares the stored pointers.
shared_ptr< _Tp > const_pointer_cast(shared_ptr< _Up > &&__r) noexcept
Convert type of shared_ptr rvalue, via const_cast
_Del * get_deleter(const shared_ptr< _Tp > &__p) noexcept
20.7.2.2.10 shared_ptr get_deleter
bool operator==(const shared_ptr< _Tp > &__a, const shared_ptr< _Up > &__b) noexcept
shared_ptr< _Tp > static_pointer_cast(shared_ptr< _Up > &&__r) noexcept
Convert type of shared_ptr rvalue, via static_cast
shared_ptr< _Tp > reinterpret_pointer_cast(const shared_ptr< _Up > &__r) noexcept
Convert type of shared_ptr, via reinterpret_cast
bool operator>=(const shared_ptr< _Tp > &__a, nullptr_t) noexcept
shared_ptr comparison with nullptr
void swap(weak_ptr< _Tp > &__a, weak_ptr< _Tp > &__b) noexcept
Swap overload for weak_ptr.
shared_ptr< _Tp > allocate_shared(const _Alloc &__a, _Args &&... __args)
Create an object that is owned by a shared_ptr.
shared_ptr< _Tp > reinterpret_pointer_cast(shared_ptr< _Up > &&__r) noexcept
Convert type of shared_ptr rvalue, via reinterpret_cast
bool operator>(nullptr_t, const shared_ptr< _Tp > &__a) noexcept
shared_ptr comparison with nullptr
bool operator>=(nullptr_t, const shared_ptr< _Tp > &__a) noexcept
shared_ptr comparison with nullptr
shared_ptr< _Tp > dynamic_pointer_cast(const shared_ptr< _Up > &__r) noexcept
Convert type of shared_ptr, via dynamic_cast
shared_ptr< _Tp > const_pointer_cast(const shared_ptr< _Up > &__r) noexcept
Convert type of shared_ptr, via const_cast
bool operator>(const shared_ptr< _Tp > &__a, const shared_ptr< _Up > &__b) noexcept
Relational operator for shared_ptr objects, compares the stored pointers.
bool operator>=(const shared_ptr< _Tp > &__a, const shared_ptr< _Up > &__b) noexcept
Relational operator for shared_ptr objects, compares the stored pointers.
bool operator!=(const shared_ptr< _Tp > &__a, nullptr_t) noexcept
shared_ptr comparison with nullptr
void swap(shared_ptr< _Tp > &__a, shared_ptr< _Tp > &__b) noexcept
Swap overload for shared_ptr.
shared_ptr< _Tp > dynamic_pointer_cast(shared_ptr< _Up > &&__r) noexcept
Convert type of shared_ptr rvalue, via dynamic_cast
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.
ISO C++ entities toplevel namespace is std.
std::basic_ostream< _CharT, _Traits > & operator<<(std::basic_ostream< _CharT, _Traits > &__os, const bitset< _Nb > &__x)
Global I/O operators for bitsets.
Template class basic_ostream.
Primary class template hash.
Define a member typedef type only if a boolean constant is true.
The standard allocator, as per C++03 [20.4.1].
A smart pointer with reference-counted copy semantics.
typename __shared_ptr< _Tp >::element_type element_type
The type pointed to by the stored pointer, remove_extent_t<_Tp>
shared_ptr(nullptr_t __p, _Deleter __d, _Alloc __a)
Construct a shared_ptr that owns a null pointer and the deleter __d.
shared_ptr(const shared_ptr< _Yp > &__r) noexcept
If __r is empty, constructs an empty shared_ptr; otherwise construct a shared_ptr that shares ownersh...
shared_ptr(shared_ptr< _Yp > &&__r) noexcept
Move-constructs a shared_ptr instance from __r.
weak_ptr< _Tp > weak_type
The corresponding weak_ptr type for this shared_ptr.
shared_ptr(_Yp *__p, _Deleter __d, _Alloc __a)
Construct a shared_ptr that owns the pointer __p and the deleter __d.
constexpr shared_ptr() noexcept
Construct an empty shared_ptr.
shared_ptr(const shared_ptr &) noexcept=default
Copy constructor.
shared_ptr(shared_ptr &&__r) noexcept
Move-constructs a shared_ptr instance from __r.
shared_ptr(_Yp *__p)
Construct a shared_ptr that owns the pointer __p.
shared_ptr(nullptr_t __p, _Deleter __d)
Construct a shared_ptr that owns a null pointer and the deleter __d.
shared_ptr(_Yp *__p, _Deleter __d)
Construct a shared_ptr that owns the pointer __p and the deleter __d.
shared_ptr(const shared_ptr< _Yp > &__r, element_type *__p) noexcept
Constructs a shared_ptr instance that stores __p and shares ownership with __r.
shared_ptr(const weak_ptr< _Yp > &__r)
Constructs a shared_ptr that shares ownership with __r and stores a copy of the pointer stored in __r...
constexpr shared_ptr(nullptr_t) noexcept
Construct an empty shared_ptr.
shared_ptr(shared_ptr< _Yp > &&__r, element_type *__p) noexcept
Constructs a shared_ptr instance that stores __p and shares ownership with __r.
A non-owning observer for a pointer owned by a shared_ptr.
Primary template owner_less.
Base class allowing use of the member function shared_from_this.
weak_ptr< const _Tp > weak_from_this() const noexcept
weak_ptr< _Tp > weak_from_this() noexcept
A simple smart pointer providing strict ownership semantics.
One of the comparison functors.
A move-only smart pointer that manages unique ownership of a resource.