50 #define _SHARED_PTR_H 1 54 namespace std _GLIBCXX_VISIBILITY(default)
56 _GLIBCXX_BEGIN_NAMESPACE_VERSION
64 template<
typename _Ch,
typename _Tr,
typename _Tp, _Lock_policy _Lp>
66 operator<<(std::basic_ostream<_Ch, _Tr>& __os,
67 const __shared_ptr<_Tp, _Lp>& __p)
74 template<
typename _Del,
typename _Tp, _Lock_policy _Lp>
79 return static_cast<_Del*
>(__p._M_get_deleter(
typeid(_Del)));
92 template<
typename _Tp>
95 template<
typename... _Args>
96 using _Constructible =
typename enable_if<
97 is_constructible<__shared_ptr<_Tp>, _Args...>::value
100 template<
typename _Arg>
101 using _Assignable =
typename enable_if<
102 is_assignable<__shared_ptr<_Tp>&, _Arg>::value,
shared_ptr&
107 using element_type =
typename __shared_ptr<_Tp>::element_type;
109 #if __cplusplus > 201402L 110 # define __cpp_lib_shared_ptr_weak_type 201606 127 template<
typename _Yp,
typename = _Constructible<_Yp*>>
144 template<
typename _Yp,
typename _Deleter,
145 typename = _Constructible<_Yp*, _Deleter>>
147 : __shared_ptr<_Tp>(__p, __d) { }
162 template<
typename _Deleter>
164 : __shared_ptr<_Tp>(__p, __d) { }
181 template<
typename _Yp,
typename _Deleter,
typename _Alloc,
182 typename = _Constructible<_Yp*, _Deleter, _Alloc>>
184 : __shared_ptr<_Tp>(__p, __d,
std::move(__a)) { }
201 template<
typename _Deleter,
typename _Alloc>
203 : __shared_ptr<_Tp>(__p, __d,
std::move(__a)) { }
223 template<
typename _Yp>
225 : __shared_ptr<_Tp>(__r, __p) { }
234 template<
typename _Yp,
235 typename = _Constructible<const shared_ptr<_Yp>&>>
237 : __shared_ptr<_Tp>(__r) { }
245 : __shared_ptr<_Tp>(std::move(__r)) { }
252 template<
typename _Yp,
typename = _Constructible<shared_ptr<_Yp>>>
254 : __shared_ptr<_Tp>(std::move(__r)) { }
264 template<
typename _Yp,
typename = _Constructible<const weak_ptr<_Yp>&>>
266 : __shared_ptr<_Tp>(__r) { }
268 #if _GLIBCXX_USE_DEPRECATED 269 template<
typename _Yp,
typename = _Constructible<auto_ptr<_Yp>>>
275 template<
typename _Yp,
typename _Del,
276 typename = _Constructible<unique_ptr<_Yp, _Del>>>
278 : __shared_ptr<_Tp>(std::move(__r)) { }
280 #if __cplusplus <= 201402L && _GLIBCXX_USE_DEPRECATED 284 template<
typename _Yp,
typename _Del,
285 _Constructible<unique_ptr<_Yp, _Del>, __sp_array_delete>* = 0>
287 : __shared_ptr<_Tp>(std::move(__r), __sp_array_delete()) { }
296 shared_ptr& operator=(
const shared_ptr&) noexcept =
default;
298 template<
typename _Yp>
299 _Assignable<const shared_ptr<_Yp>&>
302 this->__shared_ptr<_Tp>::operator=(__r);
306 #if _GLIBCXX_USE_DEPRECATED 307 template<
typename _Yp>
308 _Assignable<auto_ptr<_Yp>>
311 this->__shared_ptr<_Tp>::operator=(std::move(__r));
317 operator=(shared_ptr&& __r) noexcept
319 this->__shared_ptr<_Tp>::operator=(std::move(__r));
324 _Assignable<shared_ptr<_Yp>>
327 this->__shared_ptr<_Tp>::operator=(std::move(__r));
331 template<
typename _Yp,
typename _Del>
332 _Assignable<unique_ptr<_Yp, _Del>>
335 this->__shared_ptr<_Tp>::operator=(std::move(__r));
341 template<
typename _Alloc,
typename... _Args>
342 shared_ptr(_Sp_make_shared_tag __tag,
const _Alloc& __a,
344 : __shared_ptr<_Tp>(__tag, __a, std::forward<_Args>(__args)...)
347 template<
typename _Yp,
typename _Alloc,
typename... _Args>
353 : __shared_ptr<_Tp>(__r, std::nothrow) { }
359 template<
typename _Tp,
typename _Up>
362 {
return __a.get() == __b.get(); }
364 template<
typename _Tp>
369 template<
typename _Tp>
374 template<
typename _Tp,
typename _Up>
377 {
return __a.get() != __b.get(); }
379 template<
typename _Tp>
382 {
return (
bool)__a; }
384 template<
typename _Tp>
387 {
return (
bool)__a; }
389 template<
typename _Tp,
typename _Up>
391 operator<(const shared_ptr<_Tp>& __a,
const shared_ptr<_Up>& __b) noexcept
393 using _Tp_elt =
typename shared_ptr<_Tp>::element_type;
394 using _Up_elt =
typename shared_ptr<_Up>::element_type;
395 using _Vp =
typename common_type<_Tp_elt*, _Up_elt*>::type;
396 return less<_Vp>()(__a.get(), __b.get());
399 template<
typename _Tp>
401 operator<(const shared_ptr<_Tp>& __a, nullptr_t) noexcept
403 using _Tp_elt =
typename shared_ptr<_Tp>::element_type;
407 template<
typename _Tp>
409 operator<(nullptr_t, const shared_ptr<_Tp>& __a) noexcept
411 using _Tp_elt =
typename shared_ptr<_Tp>::element_type;
415 template<
typename _Tp,
typename _Up>
417 operator<=(const shared_ptr<_Tp>& __a,
const shared_ptr<_Up>& __b) noexcept
418 {
return !(__b < __a); }
420 template<
typename _Tp>
422 operator<=(const shared_ptr<_Tp>& __a, nullptr_t) noexcept
423 {
return !(
nullptr < __a); }
425 template<
typename _Tp>
427 operator<=(nullptr_t, const shared_ptr<_Tp>& __a) noexcept
428 {
return !(__a <
nullptr); }
430 template<
typename _Tp,
typename _Up>
433 {
return (__b < __a); }
435 template<
typename _Tp>
438 {
return nullptr < __a; }
440 template<
typename _Tp>
443 {
return __a <
nullptr; }
445 template<
typename _Tp,
typename _Up>
448 {
return !(__a < __b); }
450 template<
typename _Tp>
453 {
return !(__a <
nullptr); }
455 template<
typename _Tp>
458 {
return !(
nullptr < __a); }
460 template<
typename _Tp>
461 struct less<shared_ptr<_Tp>> :
public _Sp_less<shared_ptr<_Tp>>
465 template<
typename _Tp>
471 template<
typename _Tp,
typename _Up>
476 return _Sp(__r, static_cast<typename _Sp::element_type*>(__r.get()));
479 template<
typename _Tp,
typename _Up>
484 return _Sp(__r, const_cast<typename _Sp::element_type*>(__r.get()));
487 template<
typename _Tp,
typename _Up>
492 if (
auto* __p = dynamic_cast<typename _Sp::element_type*>(__r.get()))
493 return _Sp(__r, __p);
497 #if __cplusplus > 201402L 498 template<
typename _Tp,
typename _Up>
503 return _Sp(__r, reinterpret_cast<typename _Sp::element_type*>(__r.get()));
512 template<
typename _Tp>
515 template<
typename _Arg>
516 using _Constructible =
typename enable_if<
517 is_constructible<__weak_ptr<_Tp>, _Arg>::value
520 template<
typename _Arg>
521 using _Assignable =
typename enable_if<
522 is_assignable<__weak_ptr<_Tp>&, _Arg>::value,
weak_ptr&
526 constexpr
weak_ptr() noexcept =
default;
528 template<
typename _Yp,
529 typename = _Constructible<const shared_ptr<_Yp>&>>
531 : __weak_ptr<_Tp>(__r) { }
535 template<
typename _Yp,
typename = _Constructible<const weak_ptr<_Yp>&>>
537 : __weak_ptr<_Tp>(__r) { }
541 template<
typename _Yp,
typename = _Constructible<weak_ptr<_Yp>>>
543 : __weak_ptr<_Tp>(std::move(__r)) { }
546 operator=(
const weak_ptr& __r) noexcept =
default;
548 template<
typename _Yp>
549 _Assignable<const weak_ptr<_Yp>&>
552 this->__weak_ptr<_Tp>::operator=(__r);
556 template<
typename _Yp>
557 _Assignable<const shared_ptr<_Yp>&>
560 this->__weak_ptr<_Tp>::operator=(__r);
565 operator=(
weak_ptr&& __r) noexcept =
default;
567 template<
typename _Yp>
568 _Assignable<weak_ptr<_Yp>>
571 this->__weak_ptr<_Tp>::operator=(std::move(__r));
576 lock()
const noexcept
581 template<
typename _Tp>
588 template<
typename _Tp =
void>
597 template<
typename _Tp>
599 :
public _Sp_owner_less<shared_ptr<_Tp>, weak_ptr<_Tp>>
603 template<
typename _Tp>
605 :
public _Sp_owner_less<weak_ptr<_Tp>, shared_ptr<_Tp>>
611 template<
typename _Tp>
631 shared_from_this()
const 634 #if __cplusplus > 201402L || !defined(__STRICT_ANSI__) // c++1z or gnu++11 635 #define __cpp_lib_enable_shared_from_this 201603 637 weak_from_this() noexcept
638 {
return this->_M_weak_this; }
641 weak_from_this()
const noexcept
642 {
return this->_M_weak_this; }
646 template<
typename _Tp1>
648 _M_weak_assign(_Tp1* __p,
const __shared_count<>& __n)
const noexcept
649 { _M_weak_this._M_assign(__p, __n); }
653 __enable_shared_from_this_base(
const __shared_count<>&,
657 template<
typename, _Lock_policy>
658 friend class __shared_ptr;
674 template<
typename _Tp,
typename _Alloc,
typename... _Args>
679 std::forward<_Args>(__args)...);
689 template<
typename _Tp,
typename... _Args>
693 typedef typename std::remove_const<_Tp>::type _Tp_nc;
695 std::forward<_Args>(__args)...);
699 template<
typename _Tp>
701 :
public __hash_base<size_t, shared_ptr<_Tp>>
712 _GLIBCXX_END_NAMESPACE_VERSION
715 #endif // _SHARED_PTR_H shared_ptr(nullptr_t __p, _Deleter __d)
Construct a shared_ptr that owns a null pointer and the deleter __d.
constexpr shared_ptr() noexcept
Construct an empty shared_ptr.
Primary class template hash.
friend shared_ptr< _Yp > allocate_shared(const _Alloc &__a, _Args &&... __args)
Create an object that is owned by a shared_ptr.
ISO C++ entities toplevel namespace is std.
shared_ptr(nullptr_t __p, _Deleter __d, _Alloc __a)
Construct a shared_ptr that owns a null pointer and the deleter __d.
shared_ptr(shared_ptr &&__r) noexcept
Move-constructs a shared_ptr instance from __r.
Template class basic_ostream.
Primary template owner_less.
constexpr shared_ptr(nullptr_t) noexcept
Construct an empty shared_ptr.
A smart pointer with reference-counted copy semantics.
shared_ptr< _Tp > make_shared(_Args &&... __args)
Create an object that is owned by a shared_ptr.
void lock(_L1 &__l1, _L2 &__l2, _L3 &... __l3)
Generic lock.
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...
The standard allocator, as per [20.4].
shared_ptr(_Yp *__p)
Construct a shared_ptr that owns the pointer __p.
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...
A smart pointer with weak semantics.
shared_ptr(_Yp *__p, _Deleter __d)
Construct a shared_ptr that owns the pointer __p and the deleter __d.
shared_ptr(_Yp *__p, _Deleter __d, _Alloc __a)
Construct a shared_ptr that owns the pointer __p and the deleter __d.
A simple smart pointer providing strict ownership semantics.
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.
20.7.1.2 unique_ptr for single objects.
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.
_Del * get_deleter(const __shared_ptr< _Tp, _Lp > &__p) noexcept
20.7.2.2.10 shared_ptr get_deleter