50#define _SHARED_PTR_H 1
56_GLIBCXX_BEGIN_NAMESPACE_VERSION
64 template<
typename _Ch,
typename _Tr,
typename _Tp, _Lock_policy _Lp>
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>
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>
220 template<
typename _Tp1,
typename = _Convertible<_Tp1*>>
237 template<
typename _Tp1,
typename = _Convertible<_Tp1*>>
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
263 : __shared_ptr<_Tp>(
std::move(__r)) { }
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));
294 this->__shared_ptr<_Tp>::operator=(std::move(__r));
300 operator=(shared_ptr<_Tp1>&& __r)
noexcept
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>
323 friend shared_ptr<_Tp1>
328 : __shared_ptr<_Tp>(__r,
std::nothrow) { }
334 template<
typename _Tp1,
typename _Tp2>
336 operator==(
const shared_ptr<_Tp1>& __a,
337 const shared_ptr<_Tp2>& __b)
noexcept
338 {
return __a.get() == __b.get(); }
340 template<
typename _Tp>
342 operator==(
const shared_ptr<_Tp>& __a, nullptr_t)
noexcept
345 template<
typename _Tp>
347 operator==(nullptr_t,
const shared_ptr<_Tp>& __a)
noexcept
350 template<
typename _Tp1,
typename _Tp2>
352 operator!=(
const shared_ptr<_Tp1>& __a,
353 const shared_ptr<_Tp2>& __b)
noexcept
354 {
return __a.get() != __b.get(); }
356 template<
typename _Tp>
358 operator!=(
const shared_ptr<_Tp>& __a, nullptr_t)
noexcept
359 {
return (
bool)__a; }
361 template<
typename _Tp>
363 operator!=(nullptr_t,
const shared_ptr<_Tp>& __a)
noexcept
364 {
return (
bool)__a; }
366 template<
typename _Tp1,
typename _Tp2>
368 operator<(
const shared_ptr<_Tp1>& __a,
369 const shared_ptr<_Tp2>& __b)
noexcept
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,
388 const shared_ptr<_Tp2>& __b)
noexcept
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>
403 operator>(
const shared_ptr<_Tp1>& __a,
404 const shared_ptr<_Tp2>& __b)
noexcept
405 {
return (__b < __a); }
407 template<
typename _Tp>
409 operator>(
const shared_ptr<_Tp>& __a, nullptr_t)
noexcept
412 template<
typename _Tp>
414 operator>(nullptr_t,
const shared_ptr<_Tp>& __a)
noexcept
417 template<
typename _Tp1,
typename _Tp2>
419 operator>=(
const shared_ptr<_Tp1>& __a,
420 const shared_ptr<_Tp2>& __b)
noexcept
421 {
return !(__a < __b); }
423 template<
typename _Tp>
425 operator>=(
const shared_ptr<_Tp>& __a, nullptr_t)
noexcept
426 {
return !(__a <
nullptr); }
428 template<
typename _Tp>
430 operator>=(nullptr_t,
const shared_ptr<_Tp>& __a)
noexcept
431 {
return !(
nullptr < __a); }
433 template<
typename _Tp>
434 struct less<shared_ptr<_Tp>> :
public _Sp_less<shared_ptr<_Tp>>
438 template<
typename _Tp>
440 swap(shared_ptr<_Tp>& __a, shared_ptr<_Tp>& __b)
noexcept
444 template<
typename _Tp,
typename _Tp1>
445 inline shared_ptr<_Tp>
446 static_pointer_cast(
const shared_ptr<_Tp1>& __r)
noexcept
447 {
return shared_ptr<_Tp>(__r,
static_cast<_Tp*
>(__r.get())); }
449 template<
typename _Tp,
typename _Tp1>
450 inline shared_ptr<_Tp>
451 const_pointer_cast(
const shared_ptr<_Tp1>& __r)
noexcept
452 {
return shared_ptr<_Tp>(__r,
const_cast<_Tp*
>(__r.get())); }
454 template<
typename _Tp,
typename _Tp1>
455 inline shared_ptr<_Tp>
456 dynamic_pointer_cast(
const shared_ptr<_Tp1>& __r)
noexcept
458 if (_Tp* __p =
dynamic_cast<_Tp*
>(__r.get()))
459 return shared_ptr<_Tp>(__r, __p);
460 return shared_ptr<_Tp>();
469 template<
typename _Tp>
472 template<
typename _Ptr>
477 constexpr weak_ptr()
noexcept =
default;
479 template<
typename _Tp1,
typename = _Convertible<_Tp1*>>
485 template<
typename _Tp1,
typename = _Convertible<_Tp1*>>
491 template<
typename _Tp1,
typename = _Convertible<_Tp1*>>
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>
583 { _M_weak_this._M_assign(__p, __n); }
585 template<
typename _Tp1,
typename _Tp2>
589 const _Tp2*)
noexcept;
594 template<
typename _Tp1,
typename _Tp2>
615 template<
typename _Tp,
typename _Alloc,
typename... _Args>
616 inline shared_ptr<_Tp>
630 template<
typename _Tp,
typename...
_Args>
634 typedef typename std::remove_const<_Tp>::type
_Tp_nc;
640 template<
typename _Tp>
642 :
public __hash_base<size_t, shared_ptr<_Tp>>
651_GLIBCXX_END_NAMESPACE_VERSION
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.
shared_ptr< _Tp > make_shared(_Args &&... __args)
Create an object that is owned by a shared_ptr.
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...
_Del * get_deleter(const __shared_ptr< _Tp, _Lp > &__p) noexcept
20.7.2.2.10 shared_ptr get_deleter
constexpr shared_ptr() noexcept
Construct an empty shared_ptr.
shared_ptr(shared_ptr &&__r) noexcept
Move-constructs a shared_ptr instance from __r.
shared_ptr< _Tp > allocate_shared(const _Alloc &__a, _Args &&... __args)
Create an object that is owned by a shared_ptr.
shared_ptr(nullptr_t __p, _Deleter __d)
Construct a shared_ptr that owns a null pointer and the deleter __d.
shared_ptr(_Tp1 *__p, _Deleter __d)
Construct a shared_ptr that owns the pointer __p and the deleter __d.
shared_ptr(_Tp1 *__p)
Construct a shared_ptr that owns the pointer __p.
friend shared_ptr< _Tp1 > allocate_shared(const _Alloc &__a, _Args &&... __args)
Create an object that is owned by a shared_ptr.
shared_ptr(const shared_ptr< _Tp1 > &__r, _Tp *__p) noexcept
Constructs a shared_ptr instance that stores __p and shares ownership with __r.
constexpr shared_ptr(nullptr_t) noexcept
Construct an empty shared_ptr.
shared_ptr(shared_ptr< _Tp1 > &&__r) noexcept
Move-constructs a shared_ptr instance from __r.
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...
constexpr _Tp && forward(typename std::remove_reference< _Tp >::type &__t) noexcept
Forward an lvalue.
ISO C++ entities toplevel namespace is std.
Primary class template hash.
A smart pointer with reference-counted copy semantics.
A smart pointer with weak semantics.
Primary template owner_less.
Base class allowing use of member function shared_from_this.