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>
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>>>
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
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
490 template<
typename _Tp>
491 _GLIBCXX_NODISCARD
inline bool
499 template<
typename _Tp,
typename _Up>
500 _GLIBCXX_NODISCARD
inline bool
502 {
return !(__b < __a); }
505 template<
typename _Tp>
506 _GLIBCXX_NODISCARD
inline bool
508 {
return !(
nullptr < __a); }
511 template<
typename _Tp>
512 _GLIBCXX_NODISCARD
inline bool
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>
607 inline shared_ptr<_Tp>
610 using _Sp = shared_ptr<_Tp>;
612 static_cast<typename _Sp::element_type*
>(__r.get()));
616 template<
typename _Tp,
typename _Up>
617 inline shared_ptr<_Tp>
620 using _Sp = shared_ptr<_Tp>;
622 const_cast<typename _Sp::element_type*
>(__r.get()));
626 template<
typename _Tp,
typename _Up>
627 inline shared_ptr<_Tp>
630 using _Sp = shared_ptr<_Tp>;
631 if (
auto* __p =
dynamic_cast<typename _Sp::element_type*
>(__r.get()))
637 template<
typename _Tp,
typename _Up>
638 inline shared_ptr<_Tp>
639 reinterpret_pointer_cast(shared_ptr<_Up>&& __r) noexcept
641 using _Sp = shared_ptr<_Tp>;
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>
892 template<
typename _Tp>
893 struct _Never_valueless_alt<
std::weak_ptr<_Tp>>
899 _GLIBCXX_END_NAMESPACE_VERSION
902 #endif // _SHARED_PTR_H