50 #define _SHARED_PTR_H 1
54 namespace std _GLIBCXX_VISIBILITY(default)
56 _GLIBCXX_BEGIN_NAMESPACE_VERSION
67 template<
typename _Ch,
typename _Tr,
typename _Tp, _Lock_policy _Lp>
70 const __shared_ptr<_Tp, _Lp>& __p)
76 template<
typename _Del,
typename _Tp, _Lock_policy _Lp>
78 get_deleter(
const __shared_ptr<_Tp, _Lp>& __p) noexcept
81 return static_cast<_Del*
>(__p._M_get_deleter(
typeid(_Del)));
91 template<
typename _Del,
typename _Tp>
96 return static_cast<_Del*
>(__p._M_get_deleter(
typeid(_Del)));
120 template<
typename _Tp>
123 template<
typename... _Args>
124 using _Constructible =
typename enable_if<
128 template<
typename _Arg>
138 #if __cplusplus >= 201703L
139 # define __cpp_lib_shared_ptr_weak_type 201606
157 template<
typename _Yp,
typename = _Constructible<_Yp*>>
174 template<
typename _Yp,
typename _Deleter,
175 typename = _Constructible<_Yp*, _Deleter>>
177 : __shared_ptr<_Tp>(__p,
std::
move(__d)) { }
192 template<
typename _Deleter>
194 : __shared_ptr<_Tp>(__p,
std::
move(__d)) { }
211 template<
typename _Yp,
typename _Deleter,
typename _Alloc,
212 typename = _Constructible<_Yp*, _Deleter, _Alloc>>
231 template<
typename _Deleter,
typename _Alloc>
255 template<
typename _Yp>
257 : __shared_ptr<_Tp>(__r, __p) { }
259 #if __cplusplus > 201703L
282 template<
typename _Yp>
284 : __shared_ptr<_Tp>(
std::move(__r), __p) { }
293 template<
typename _Yp,
294 typename = _Constructible<const shared_ptr<_Yp>&>>
296 : __shared_ptr<_Tp>(__r) { }
311 template<
typename _Yp,
typename = _Constructible<shared_ptr<_Yp>>>
323 template<
typename _Yp,
typename = _Constructible<const weak_ptr<_Yp>&>>
325 : __shared_ptr<_Tp>(__r) { }
327 #if _GLIBCXX_USE_DEPRECATED
328 #pragma GCC diagnostic push
329 #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
330 template<
typename _Yp,
typename = _Constructible<auto_ptr<_Yp>>>
332 #pragma GCC diagnostic pop
337 template<
typename _Yp,
typename _Del,
338 typename = _Constructible<unique_ptr<_Yp, _Del>>>
340 : __shared_ptr<_Tp>(
std::
move(__r)) { }
342 #if __cplusplus <= 201402L && _GLIBCXX_USE_DEPRECATED
346 template<
typename _Yp,
typename _Del,
347 _Constructible<unique_ptr<_Yp, _Del>, __sp_array_delete>* = 0>
349 : __shared_ptr<_Tp>(
std::
move(__r), __sp_array_delete()) { }
360 template<
typename _Yp>
361 _Assignable<const shared_ptr<_Yp>&>
364 this->__shared_ptr<_Tp>::operator=(__r);
368 #if _GLIBCXX_USE_DEPRECATED
369 #pragma GCC diagnostic push
370 #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
371 template<
typename _Yp>
372 _Assignable<auto_ptr<_Yp>>
373 operator=(auto_ptr<_Yp>&& __r)
375 this->__shared_ptr<_Tp>::operator=(
std::move(__r));
378 #pragma GCC diagnostic pop
384 this->__shared_ptr<_Tp>::operator=(
std::move(__r));
389 _Assignable<shared_ptr<_Yp>>
390 operator=(shared_ptr<_Yp>&& __r) noexcept
392 this->__shared_ptr<_Tp>::operator=(
std::move(__r));
396 template<
typename _Yp,
typename _Del>
397 _Assignable<unique_ptr<_Yp, _Del>>
398 operator=(unique_ptr<_Yp, _Del>&& __r)
400 this->__shared_ptr<_Tp>::operator=(
std::move(__r));
406 template<
typename _Alloc,
typename... _Args>
407 shared_ptr(_Sp_alloc_shared_tag<_Alloc> __tag, _Args&&... __args)
408 : __shared_ptr<_Tp>(__tag,
std::
forward<_Args>(__args)...)
411 template<
typename _Yp,
typename _Alloc,
typename... _Args>
412 friend shared_ptr<_Yp>
413 allocate_shared(
const _Alloc& __a, _Args&&... __args);
416 shared_ptr(
const weak_ptr<_Tp>& __r, std::nothrow_t)
417 : __shared_ptr<_Tp>(__r,
std::nothrow) { }
419 friend class weak_ptr<_Tp>;
422 #if __cpp_deduction_guides >= 201606
423 template<
typename _Tp>
424 shared_ptr(weak_ptr<_Tp>) -> shared_ptr<_Tp>;
425 template<
typename _Tp,
typename _Del>
426 shared_ptr(unique_ptr<_Tp, _Del>) -> shared_ptr<_Tp>;
434 template<
typename _Tp,
typename _Up>
435 _GLIBCXX_NODISCARD
inline bool
437 {
return __a.get() == __b.get(); }
440 template<
typename _Tp>
441 _GLIBCXX_NODISCARD
inline bool
445 #ifdef __cpp_lib_three_way_comparison
446 template<
typename _Tp,
typename _Up>
447 inline strong_ordering
450 {
return compare_three_way()(__a.get(), __b.get()); }
452 template<
typename _Tp>
453 inline strong_ordering
454 operator<=>(
const shared_ptr<_Tp>& __a, nullptr_t) noexcept
457 return compare_three_way()(__a.get(),
static_cast<pointer
>(
nullptr));
461 template<
typename _Tp>
462 _GLIBCXX_NODISCARD
inline bool
467 template<
typename _Tp,
typename _Up>
468 _GLIBCXX_NODISCARD
inline bool
470 {
return __a.get() != __b.get(); }
473 template<
typename _Tp>
474 _GLIBCXX_NODISCARD
inline bool
476 {
return (
bool)__a; }
479 template<
typename _Tp>
480 _GLIBCXX_NODISCARD
inline bool
482 {
return (
bool)__a; }
485 template<
typename _Tp,
typename _Up>
486 _GLIBCXX_NODISCARD
inline bool
492 return less<_Vp>()(__a.get(), __b.get());
496 template<
typename _Tp>
497 _GLIBCXX_NODISCARD
inline bool
505 template<
typename _Tp>
506 _GLIBCXX_NODISCARD
inline bool
514 template<
typename _Tp,
typename _Up>
515 _GLIBCXX_NODISCARD
inline bool
517 {
return !(__b < __a); }
520 template<
typename _Tp>
521 _GLIBCXX_NODISCARD
inline bool
523 {
return !(
nullptr < __a); }
526 template<
typename _Tp>
527 _GLIBCXX_NODISCARD
inline bool
529 {
return !(__a <
nullptr); }
532 template<
typename _Tp,
typename _Up>
533 _GLIBCXX_NODISCARD
inline bool
535 {
return (__b < __a); }
538 template<
typename _Tp>
539 _GLIBCXX_NODISCARD
inline bool
541 {
return nullptr < __a; }
544 template<
typename _Tp>
545 _GLIBCXX_NODISCARD
inline bool
547 {
return __a <
nullptr; }
550 template<
typename _Tp,
typename _Up>
551 _GLIBCXX_NODISCARD
inline bool
553 {
return !(__a < __b); }
556 template<
typename _Tp>
557 _GLIBCXX_NODISCARD
inline bool
559 {
return !(__a <
nullptr); }
562 template<
typename _Tp>
563 _GLIBCXX_NODISCARD
inline bool
565 {
return !(
nullptr < __a); }
571 template<
typename _Tp>
579 template<
typename _Tp,
typename _Up>
584 return _Sp(__r,
static_cast<typename _Sp::element_type*
>(__r.get()));
588 template<
typename _Tp,
typename _Up>
593 return _Sp(__r,
const_cast<typename _Sp::element_type*
>(__r.get()));
597 template<
typename _Tp,
typename _Up>
602 if (
auto* __p =
dynamic_cast<typename _Sp::element_type*
>(__r.get()))
603 return _Sp(__r, __p);
607 #if __cplusplus >= 201703L
609 template<
typename _Tp,
typename _Up>
614 return _Sp(__r,
reinterpret_cast<typename _Sp::element_type*
>(__r.get()));
617 #if __cplusplus > 201703L
622 template<
typename _Tp,
typename _Up>
623 inline shared_ptr<_Tp>
626 using _Sp = shared_ptr<_Tp>;
628 static_cast<typename _Sp::element_type*
>(__r.get()));
632 template<
typename _Tp,
typename _Up>
633 inline shared_ptr<_Tp>
636 using _Sp = shared_ptr<_Tp>;
638 const_cast<typename _Sp::element_type*
>(__r.get()));
642 template<
typename _Tp,
typename _Up>
643 inline shared_ptr<_Tp>
646 using _Sp = shared_ptr<_Tp>;
647 if (
auto* __p =
dynamic_cast<typename _Sp::element_type*
>(__r.get()))
653 template<
typename _Tp,
typename _Up>
654 inline shared_ptr<_Tp>
655 reinterpret_pointer_cast(shared_ptr<_Up>&& __r) noexcept
657 using _Sp = shared_ptr<_Tp>;
659 reinterpret_cast<typename _Sp::element_type*
>(__r.get()));
684 template<
typename _Tp>
687 template<
typename _Arg>
688 using _Constructible =
typename enable_if<
692 template<
typename _Arg>
698 constexpr
weak_ptr() noexcept =
default;
700 template<
typename _Yp,
701 typename = _Constructible<const shared_ptr<_Yp>&>>
703 : __weak_ptr<_Tp>(__r) { }
707 template<
typename _Yp,
typename = _Constructible<const weak_ptr<_Yp>&>>
709 : __weak_ptr<_Tp>(__r) { }
713 template<
typename _Yp,
typename = _Constructible<weak_ptr<_Yp>>>
718 operator=(
const weak_ptr& __r) noexcept =
default;
720 template<
typename _Yp>
721 _Assignable<const weak_ptr<_Yp>&>
724 this->__weak_ptr<_Tp>::operator=(__r);
728 template<
typename _Yp>
729 _Assignable<const shared_ptr<_Yp>&>
732 this->__weak_ptr<_Tp>::operator=(__r);
737 operator=(
weak_ptr&& __r) noexcept =
default;
739 template<
typename _Yp>
740 _Assignable<weak_ptr<_Yp>>
743 this->__weak_ptr<_Tp>::operator=(
std::move(__r));
748 lock()
const noexcept
752 #if __cpp_deduction_guides >= 201606
753 template<
typename _Tp>
760 template<
typename _Tp>
767 template<
typename _Tp =
void>
776 template<
typename _Tp>
778 :
public _Sp_owner_less<shared_ptr<_Tp>, weak_ptr<_Tp>>
782 template<
typename _Tp>
784 :
public _Sp_owner_less<weak_ptr<_Tp>, shared_ptr<_Tp>>
790 template<
typename _Tp>
810 shared_from_this()
const
813 #if __cplusplus > 201402L || !defined(__STRICT_ANSI__)
814 #define __cpp_lib_enable_shared_from_this 201603
816 weak_from_this() noexcept
817 {
return this->_M_weak_this; }
820 weak_from_this()
const noexcept
821 {
return this->_M_weak_this; }
825 template<
typename _Tp1>
827 _M_weak_assign(_Tp1* __p,
const __shared_count<>& __n)
const noexcept
828 { _M_weak_this._M_assign(__p, __n); }
832 __enable_shared_from_this_base(
const __shared_count<>&,
836 template<
typename, _Lock_policy>
837 friend class __shared_ptr;
855 template<
typename _Tp,
typename _Alloc,
typename... _Args>
862 std::forward<_Args>(__args)...);
872 template<
typename _Tp,
typename... _Args>
876 typedef typename std::remove_cv<_Tp>::type _Tp_nc;
878 std::forward<_Args>(__args)...);
882 template<
typename _Tp>
884 :
public __hash_base<size_t, shared_ptr<_Tp>>
896 #if __cplusplus >= 201703L
897 namespace __detail::__variant
899 template<
typename>
struct _Never_valueless_alt;
903 template<
typename _Tp>
910 template<
typename _Tp>
911 struct _Never_valueless_alt<
std::weak_ptr<_Tp>>
917 _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.
_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
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.
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.
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.
__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
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.
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.
A non-owning observer for a pointer owned by a shared_ptr.
Primary template owner_less.
Base class allowing use of member function shared_from_this.
One of the comparison functors.
20.7.1.2 unique_ptr for single objects.
A simple smart pointer providing strict ownership semantics.