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>
69 operator<<(std::basic_ostream<_Ch, _Tr>& __os,
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>
136 using element_type =
typename __shared_ptr<_Tp>::element_type;
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>>>
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()) { }
358 shared_ptr& operator=(
const shared_ptr&) noexcept =
default;
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>>
375 this->__shared_ptr<_Tp>::operator=(
std::move(__r));
378 #pragma GCC diagnostic pop 382 operator=(shared_ptr&& __r) noexcept
384 this->__shared_ptr<_Tp>::operator=(
std::move(__r));
389 _Assignable<shared_ptr<_Yp>>
392 this->__shared_ptr<_Tp>::operator=(
std::move(__r));
396 template<
typename _Yp,
typename _Del>
397 _Assignable<unique_ptr<_Yp, _Del>>
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>
413 allocate_shared(
const _Alloc& __a, _Args&&... __args);
417 : __shared_ptr<_Tp>(__r, std::nothrow) { }
422 #if __cpp_deduction_guides >= 201606 423 template<
typename _Tp>
425 template<
typename _Tp,
typename _Del>
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 446 template<
typename _Tp>
447 _GLIBCXX_NODISCARD
inline bool 452 template<
typename _Tp,
typename _Up>
453 _GLIBCXX_NODISCARD
inline bool 455 {
return __a.get() != __b.get(); }
458 template<
typename _Tp>
459 _GLIBCXX_NODISCARD
inline bool 461 {
return (
bool)__a; }
464 template<
typename _Tp>
465 _GLIBCXX_NODISCARD
inline bool 467 {
return (
bool)__a; }
470 template<
typename _Tp,
typename _Up>
471 _GLIBCXX_NODISCARD
inline bool 477 return less<_Vp>()(__a.get(), __b.get());
481 template<
typename _Tp>
482 _GLIBCXX_NODISCARD
inline bool 483 operator<(const shared_ptr<_Tp>& __a, nullptr_t) noexcept
490 template<
typename _Tp>
491 _GLIBCXX_NODISCARD
inline bool 492 operator<(nullptr_t, const shared_ptr<_Tp>& __a) noexcept
499 template<
typename _Tp,
typename _Up>
500 _GLIBCXX_NODISCARD
inline bool 502 {
return !(__b < __a); }
505 template<
typename _Tp>
506 _GLIBCXX_NODISCARD
inline bool 507 operator<=(const shared_ptr<_Tp>& __a, nullptr_t) noexcept
508 {
return !(
nullptr < __a); }
511 template<
typename _Tp>
512 _GLIBCXX_NODISCARD
inline bool 513 operator<=(nullptr_t, const shared_ptr<_Tp>& __a) noexcept
514 {
return !(__a <
nullptr); }
517 template<
typename _Tp,
typename _Up>
518 _GLIBCXX_NODISCARD
inline bool 520 {
return (__b < __a); }
523 template<
typename _Tp>
524 _GLIBCXX_NODISCARD
inline bool 526 {
return nullptr < __a; }
529 template<
typename _Tp>
530 _GLIBCXX_NODISCARD
inline bool 532 {
return __a <
nullptr; }
535 template<
typename _Tp,
typename _Up>
536 _GLIBCXX_NODISCARD
inline bool 538 {
return !(__a < __b); }
541 template<
typename _Tp>
542 _GLIBCXX_NODISCARD
inline bool 544 {
return !(__a <
nullptr); }
547 template<
typename _Tp>
548 _GLIBCXX_NODISCARD
inline bool 550 {
return !(
nullptr < __a); }
555 template<
typename _Tp>
563 template<
typename _Tp,
typename _Up>
568 return _Sp(__r, static_cast<typename _Sp::element_type*>(__r.get()));
572 template<
typename _Tp,
typename _Up>
577 return _Sp(__r, const_cast<typename _Sp::element_type*>(__r.get()));
581 template<
typename _Tp,
typename _Up>
586 if (
auto* __p = dynamic_cast<typename _Sp::element_type*>(__r.get()))
587 return _Sp(__r, __p);
591 #if __cplusplus >= 201703L 593 template<
typename _Tp,
typename _Up>
598 return _Sp(__r, reinterpret_cast<typename _Sp::element_type*>(__r.get()));
601 #if __cplusplus > 201703L 606 template<
typename _Tp,
typename _Up>
612 static_cast<typename _Sp::element_type*>(__r.get()));
616 template<
typename _Tp,
typename _Up>
622 const_cast<typename _Sp::element_type*>(__r.get()));
626 template<
typename _Tp,
typename _Up>
631 if (
auto* __p = dynamic_cast<typename _Sp::element_type*>(__r.get()))
637 template<
typename _Tp,
typename _Up>
643 reinterpret_cast<typename _Sp::element_type*>(__r.get()));
668 template<
typename _Tp>
671 template<
typename _Arg>
672 using _Constructible =
typename enable_if<
676 template<
typename _Arg>
682 constexpr
weak_ptr() noexcept =
default;
684 template<
typename _Yp,
685 typename = _Constructible<const shared_ptr<_Yp>&>>
687 : __weak_ptr<_Tp>(__r) { }
691 template<
typename _Yp,
typename = _Constructible<const weak_ptr<_Yp>&>>
693 : __weak_ptr<_Tp>(__r) { }
697 template<
typename _Yp,
typename = _Constructible<weak_ptr<_Yp>>>
702 operator=(
const weak_ptr& __r) noexcept =
default;
704 template<
typename _Yp>
705 _Assignable<const weak_ptr<_Yp>&>
708 this->__weak_ptr<_Tp>::operator=(__r);
712 template<
typename _Yp>
713 _Assignable<const shared_ptr<_Yp>&>
716 this->__weak_ptr<_Tp>::operator=(__r);
721 operator=(
weak_ptr&& __r) noexcept =
default;
723 template<
typename _Yp>
724 _Assignable<weak_ptr<_Yp>>
727 this->__weak_ptr<_Tp>::operator=(
std::move(__r));
732 lock()
const noexcept
736 #if __cpp_deduction_guides >= 201606 737 template<
typename _Tp>
744 template<
typename _Tp>
751 template<
typename _Tp =
void>
760 template<
typename _Tp>
762 :
public _Sp_owner_less<shared_ptr<_Tp>, weak_ptr<_Tp>>
766 template<
typename _Tp>
768 :
public _Sp_owner_less<weak_ptr<_Tp>, shared_ptr<_Tp>>
774 template<
typename _Tp>
794 shared_from_this()
const 797 #if __cplusplus > 201402L || !defined(__STRICT_ANSI__) // c++1z or gnu++11 798 #define __cpp_lib_enable_shared_from_this 201603 800 weak_from_this() noexcept
801 {
return this->_M_weak_this; }
804 weak_from_this()
const noexcept
805 {
return this->_M_weak_this; }
809 template<
typename _Tp1>
811 _M_weak_assign(_Tp1* __p,
const __shared_count<>& __n)
const noexcept
812 { _M_weak_this._M_assign(__p, __n); }
816 __enable_shared_from_this_base(
const __shared_count<>&,
820 template<
typename, _Lock_policy>
821 friend class __shared_ptr;
839 template<
typename _Tp,
typename _Alloc,
typename... _Args>
844 std::forward<_Args>(__args)...);
854 template<
typename _Tp,
typename... _Args>
858 typedef typename std::remove_cv<_Tp>::type _Tp_nc;
860 std::forward<_Args>(__args)...);
864 template<
typename _Tp>
866 :
public __hash_base<size_t, shared_ptr<_Tp>>
878 #if __cplusplus >= 201703L 879 namespace __detail::__variant
881 template<
typename>
struct _Never_valueless_alt;
885 template<
typename _Tp>
886 struct _Never_valueless_alt<std::
shared_ptr<_Tp>>
892 template<
typename _Tp>
893 struct _Never_valueless_alt<std::
weak_ptr<_Tp>>
899 _GLIBCXX_END_NAMESPACE_VERSION
902 #endif // _SHARED_PTR_H A non-owning observer for a pointer owned by a shared_ptr.
constexpr shared_ptr(nullptr_t) noexcept
Construct an empty shared_ptr.
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(shared_ptr< _Yp > &&__r) noexcept
Move-constructs a shared_ptr instance from __r.
Base class allowing use of member function shared_from_this.
shared_ptr(shared_ptr &&__r) noexcept
Move-constructs a shared_ptr instance from __r.
A simple smart pointer providing strict ownership semantics.
void lock(_L1 &__l1, _L2 &__l2, _L3 &... __l3)
Generic lock.
bool operator!=(nullptr_t, const shared_ptr< _Tp > &__a) noexcept
shared_ptr comparison with nullptr
Template class basic_ostream.
20.7.1.2 unique_ptr for single objects.
bool operator==(const shared_ptr< _Tp > &__a, const shared_ptr< _Up > &__b) noexcept
Equality operator for shared_ptr objects, compares the stored pointers.
A smart pointer with reference-counted copy semantics.
shared_ptr< _Tp > static_pointer_cast(const shared_ptr< _Up > &__r) noexcept
Convert type of shared_ptr, via static_cast
constexpr std::remove_reference< _Tp >::type && move(_Tp &&__t) noexcept
Convert a value to an rvalue.
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(_Yp *__p, _Deleter __d)
Construct a shared_ptr that owns the pointer __p and the deleter __d.
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(const weak_ptr< _Yp > &__r)
Constructs a shared_ptr that shares ownership with __r and stores a copy of the pointer stored in __r...
Primary template owner_less.
constexpr shared_ptr() noexcept
Construct an empty shared_ptr.
bool operator>=(nullptr_t, const shared_ptr< _Tp > &__a) noexcept
shared_ptr comparison with nullptr
_Del * get_deleter(const shared_ptr< _Tp > &__p) noexcept
20.7.2.2.10 shared_ptr get_deleter
The standard allocator, as per [20.4].
bool operator>=(const shared_ptr< _Tp > &__a, nullptr_t) noexcept
shared_ptr comparison with nullptr
bool operator>(const shared_ptr< _Tp > &__a, const shared_ptr< _Up > &__b) noexcept
Relational operator for shared_ptr objects, compares the stored pointers.
typename __shared_ptr< _Tp >::element_type element_type
The type pointed to by the stored pointer, remove_extent_t<_Tp>
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(_Yp *__p, _Deleter __d, _Alloc __a)
Construct a shared_ptr that owns the pointer __p and the deleter __d.
shared_ptr< _Tp > dynamic_pointer_cast(const shared_ptr< _Up > &__r) noexcept
Convert type of shared_ptr, via dynamic_cast
bool operator>=(const shared_ptr< _Tp > &__a, const shared_ptr< _Up > &__b) noexcept
Relational operator for shared_ptr objects, compares the stored pointers.
Primary class template hash.
shared_ptr< _Tp > const_pointer_cast(const shared_ptr< _Up > &__r) noexcept
Convert type of shared_ptr, via const_cast
void swap(weak_ptr< _Tp > &__a, weak_ptr< _Tp > &__b) noexcept
Swap overload for weak_ptr.
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(nullptr_t __p, _Deleter __d)
Construct a shared_ptr that owns a null pointer and the deleter __d.
ISO C++ entities toplevel namespace is std.
shared_ptr(const shared_ptr< _Yp > &__r, element_type *__p) noexcept
Constructs a shared_ptr instance that stores __p and shares ownership with __r.
One of the comparison functors.
shared_ptr(_Yp *__p)
Construct a shared_ptr that owns the pointer __p.
shared_ptr(nullptr_t __p, _Deleter __d, _Alloc __a)
Construct a shared_ptr that owns a null pointer and the deleter __d.
shared_ptr< _Tp > make_shared(_Args &&... __args)
Create an object that is owned by a shared_ptr.
Define a member typedef type only if a boolean constant is true.
shared_ptr< _Tp > allocate_shared(const _Alloc &__a, _Args &&... __args)
Create an object that is owned by a shared_ptr.