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 _Ptr>
97 =
typename enable_if<is_convertible<_Ptr, _Tp*>::value>::type;
105 : __shared_ptr<_Tp>() { }
115 template<
typename _Tp1>
117 : __shared_ptr<_Tp>(__p) { }
132 template<
typename _Tp1,
typename _Deleter>
134 : __shared_ptr<_Tp>(__p, __d) { }
149 template<
typename _Deleter>
151 : __shared_ptr<_Tp>(__p, __d) { }
168 template<
typename _Tp1,
typename _Deleter,
typename _Alloc>
170 : __shared_ptr<_Tp>(__p, __d,
std::move(__a)) { }
187 template<
typename _Deleter,
typename _Alloc>
189 : __shared_ptr<_Tp>(__p, __d,
std::move(__a)) { }
209 template<
typename _Tp1>
211 : __shared_ptr<_Tp>(__r, __p) { }
220 template<
typename _Tp1,
typename = _Convertible<_Tp1*>>
222 : __shared_ptr<_Tp>(__r) { }
230 : __shared_ptr<_Tp>(
std::move(__r)) { }
237 template<
typename _Tp1,
typename = _Convertible<_Tp1*>>
239 : __shared_ptr<_Tp>(
std::move(__r)) { }
249 template<
typename _Tp1>
251 : __shared_ptr<_Tp>(__r) { }
253 #if _GLIBCXX_USE_DEPRECATED 254 template<
typename _Tp1>
260 template<
typename _Tp1,
typename _Del,
typename 261 = _Convertible<typename unique_ptr<_Tp1, _Del>::pointer>>
263 : __shared_ptr<_Tp>(std::move(__r)) { }
271 shared_ptr& operator=(
const shared_ptr&) noexcept =
default;
273 template<
typename _Tp1>
277 this->__shared_ptr<_Tp>::operator=(__r);
281 #if _GLIBCXX_USE_DEPRECATED 282 template<
typename _Tp1>
286 this->__shared_ptr<_Tp>::operator=(std::move(__r));
292 operator=(shared_ptr&& __r) noexcept
294 this->__shared_ptr<_Tp>::operator=(std::move(__r));
302 this->__shared_ptr<_Tp>::operator=(std::move(__r));
306 template<
typename _Tp1,
typename _Del>
310 this->__shared_ptr<_Tp>::operator=(std::move(__r));
316 template<
typename _Alloc,
typename... _Args>
317 shared_ptr(_Sp_make_shared_tag __tag,
const _Alloc& __a,
319 : __shared_ptr<_Tp>(__tag, __a, std::forward<_Args>(__args)...)
322 template<
typename _Tp1,
typename _Alloc,
typename... _Args>
328 : __shared_ptr<_Tp>(__r, std::nothrow) { }
334 template<
typename _Tp1,
typename _Tp2>
338 {
return __a.get() == __b.get(); }
340 template<
typename _Tp>
345 template<
typename _Tp>
350 template<
typename _Tp1,
typename _Tp2>
354 {
return __a.get() != __b.get(); }
356 template<
typename _Tp>
359 {
return (
bool)__a; }
361 template<
typename _Tp>
364 {
return (
bool)__a; }
366 template<
typename _Tp1,
typename _Tp2>
368 operator<(const shared_ptr<_Tp1>& __a,
371 typedef typename std::common_type<_Tp1*, _Tp2*>::type _CT;
375 template<
typename _Tp>
377 operator<(const shared_ptr<_Tp>& __a, nullptr_t) noexcept
380 template<
typename _Tp>
382 operator<(nullptr_t, const shared_ptr<_Tp>& __a) noexcept
385 template<
typename _Tp1,
typename _Tp2>
387 operator<=(const shared_ptr<_Tp1>& __a,
389 {
return !(__b < __a); }
391 template<
typename _Tp>
393 operator<=(const shared_ptr<_Tp>& __a, nullptr_t) noexcept
394 {
return !(
nullptr < __a); }
396 template<
typename _Tp>
398 operator<=(nullptr_t, const shared_ptr<_Tp>& __a) noexcept
399 {
return !(__a <
nullptr); }
401 template<
typename _Tp1,
typename _Tp2>
405 {
return (__b < __a); }
407 template<
typename _Tp>
412 template<
typename _Tp>
417 template<
typename _Tp1,
typename _Tp2>
421 {
return !(__a < __b); }
423 template<
typename _Tp>
426 {
return !(__a <
nullptr); }
428 template<
typename _Tp>
431 {
return !(
nullptr < __a); }
433 template<
typename _Tp>
434 struct less<shared_ptr<_Tp>> :
public _Sp_less<shared_ptr<_Tp>>
438 template<
typename _Tp>
444 template<
typename _Tp,
typename _Tp1>
449 template<
typename _Tp,
typename _Tp1>
454 template<
typename _Tp,
typename _Tp1>
458 if (_Tp* __p = dynamic_cast<_Tp*>(__r.get()))
469 template<
typename _Tp>
472 template<
typename _Ptr>
474 =
typename enable_if<is_convertible<_Ptr, _Tp*>::value>::type;
477 constexpr
weak_ptr() noexcept =
default;
479 template<
typename _Tp1,
typename = _Convertible<_Tp1*>>
481 : __weak_ptr<_Tp>(__r) { }
485 template<
typename _Tp1,
typename = _Convertible<_Tp1*>>
487 : __weak_ptr<_Tp>(__r) { }
491 template<
typename _Tp1,
typename = _Convertible<_Tp1*>>
493 : __weak_ptr<_Tp>(std::move(__r)) { }
496 operator=(
const weak_ptr& __r) noexcept =
default;
498 template<
typename _Tp1>
502 this->__weak_ptr<_Tp>::operator=(__r);
506 template<
typename _Tp1>
510 this->__weak_ptr<_Tp>::operator=(__r);
515 operator=(
weak_ptr&& __r) noexcept =
default;
517 template<
typename _Tp1>
521 this->__weak_ptr<_Tp>::operator=(std::move(__r));
526 lock()
const noexcept
531 template<
typename _Tp>
538 template<
typename _Tp>
542 template<
typename _Tp>
544 :
public _Sp_owner_less<shared_ptr<_Tp>, weak_ptr<_Tp>>
548 template<
typename _Tp>
550 :
public _Sp_owner_less<weak_ptr<_Tp>, shared_ptr<_Tp>>
556 template<
typename _Tp>
576 shared_from_this()
const 580 template<
typename _Tp1>
582 _M_weak_assign(_Tp1* __p,
const __shared_count<>& __n)
const noexcept
583 { _M_weak_this._M_assign(__p, __n); }
585 template<
typename _Tp1,
typename _Tp2>
587 __enable_shared_from_this_helper(
const __shared_count<>&,
589 const _Tp2*) noexcept;
594 template<
typename _Tp1,
typename _Tp2>
596 __enable_shared_from_this_helper(
const __shared_count<>& __pn,
598 __pe,
const _Tp2* __px) noexcept
601 __pe->_M_weak_assign(const_cast<_Tp2*>(__px), __pn);
615 template<
typename _Tp,
typename _Alloc,
typename... _Args>
620 std::forward<_Args>(__args)...);
630 template<
typename _Tp,
typename... _Args>
634 typedef typename std::remove_const<_Tp>::type _Tp_nc;
636 std::forward<_Args>(__args)...);
640 template<
typename _Tp>
642 :
public __hash_base<size_t, shared_ptr<_Tp>>
651 _GLIBCXX_END_NAMESPACE_VERSION
654 #endif // _SHARED_PTR_H shared_ptr(const shared_ptr< _Tp1 > &__r, _Tp *__p) noexcept
Constructs a shared_ptr instance that stores __p and shares ownership with __r.
_Del * get_deleter(const __shared_ptr< _Tp, _Lp > &__p) noexcept
20.7.2.2.10 shared_ptr get_deleter
shared_ptr(_Tp1 *__p, _Deleter __d, _Alloc __a)
Construct a shared_ptr that owns the pointer __p and the deleter __d.
shared_ptr(nullptr_t __p, _Deleter __d, _Alloc __a)
Construct a shared_ptr that owns a null pointer and the deleter __d.
friend shared_ptr< _Tp1 > allocate_shared(const _Alloc &__a, _Args &&...__args)
Create an object that is owned by a shared_ptr.
The standard allocator, as per [20.4].
Template class basic_ostream.
shared_ptr(nullptr_t __p, _Deleter __d)
Construct a shared_ptr that owns a null pointer and the deleter __d.
Partial specializations for pointer types.
A smart pointer with reference-counted copy semantics.
One of the comparison functors.
Primary class template hash.
shared_ptr(const shared_ptr< _Tp1 > &__r) noexcept
If __r is empty, constructs an empty shared_ptr; otherwise construct a shared_ptr that shares ownersh...
shared_ptr(_Tp1 *__p, _Deleter __d)
Construct a shared_ptr that owns the pointer __p and the deleter __d.
constexpr shared_ptr(nullptr_t) noexcept
Construct an empty shared_ptr.
A smart pointer with weak semantics.
shared_ptr(shared_ptr &&__r) noexcept
Move-constructs a shared_ptr instance from __r.
shared_ptr< _Tp > make_shared(_Args &&...__args)
Create an object that is owned by a shared_ptr.
20.7.1.2 unique_ptr for single objects.
A simple smart pointer providing strict ownership semantics.
Primary template owner_less.
shared_ptr(const weak_ptr< _Tp1 > &__r)
Constructs a shared_ptr that shares ownership with __r and stores a copy of the pointer stored in __r...
shared_ptr(_Tp1 *__p)
Construct a shared_ptr that owns the pointer __p.
void lock(_L1 &__l1, _L2 &__l2, _L3 &...__l3)
Generic lock.
constexpr shared_ptr() noexcept
Construct an empty shared_ptr.
ISO C++ entities toplevel namespace is std.
Base class allowing use of member function shared_from_this.
shared_ptr(shared_ptr< _Tp1 > &&__r) noexcept
Move-constructs a shared_ptr instance from __r.