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>
101 : __shared_ptr<_Tp>() { }
111 template<typename _Tp1>
113 : __shared_ptr<_Tp>(__p) { }
128 template<
typename _Tp1,
typename _Deleter>
130 : __shared_ptr<_Tp>(__p, __d) { }
145 template<
typename _Deleter>
147 : __shared_ptr<_Tp>(__p, __d) { }
164 template<
typename _Tp1,
typename _Deleter,
typename _Alloc>
166 : __shared_ptr<_Tp>(__p, __d, std::move(__a)) { }
183 template<
typename _Deleter,
typename _Alloc>
185 : __shared_ptr<_Tp>(__p, __d, std::move(__a)) { }
205 template<
typename _Tp1>
207 : __shared_ptr<_Tp>(__r, __p) { }
216 template<
typename _Tp1,
typename =
typename
219 : __shared_ptr<_Tp>(__r) { }
227 : __shared_ptr<_Tp>(std::move(__r)) { }
234 template<
typename _Tp1,
typename =
typename
237 : __shared_ptr<_Tp>(std::move(__r)) { }
247 template<
typename _Tp1>
249 : __shared_ptr<_Tp>(__r) { }
251 #if _GLIBCXX_USE_DEPRECATED
252 template<
typename _Tp1>
254 : __shared_ptr<_Tp>(std::move(__r)) { }
257 template<
typename _Tp1,
typename _Del>
259 : __shared_ptr<_Tp>(std::move(__r)) { }
267 : __shared_ptr<_Tp>(__p) { }
271 template<typename _Tp1>
273 operator=(const
shared_ptr<_Tp1>& __r) noexcept
275 this->__shared_ptr<_Tp>::operator=(__r);
279 #if _GLIBCXX_USE_DEPRECATED
280 template<
typename _Tp1>
284 this->__shared_ptr<_Tp>::operator=(std::move(__r));
292 this->__shared_ptr<_Tp>::operator=(std::move(__r));
298 operator=(shared_ptr<_Tp1>&& __r) noexcept
300 this->__shared_ptr<_Tp>::operator=(std::move(__r));
304 template<
typename _Tp1,
typename _Del>
308 this->__shared_ptr<_Tp>::operator=(std::move(__r));
314 template<
typename _Alloc,
typename... _Args>
315 shared_ptr(_Sp_make_shared_tag __tag,
const _Alloc& __a,
317 : __shared_ptr<_Tp>(__tag, __a, std::
forward<_Args>(__args)...)
320 template<
typename _Tp1,
typename _Alloc,
typename... _Args>
321 friend shared_ptr<_Tp1>
326 template<
typename _Tp1,
typename _Tp2>
328 operator==(
const shared_ptr<_Tp1>& __a,
329 const shared_ptr<_Tp2>& __b) noexcept
330 {
return __a.get() == __b.get(); }
332 template<
typename _Tp>
334 operator==(
const shared_ptr<_Tp>& __a, nullptr_t) noexcept
337 template<
typename _Tp>
339 operator==(nullptr_t,
const shared_ptr<_Tp>& __a) noexcept
342 template<
typename _Tp1,
typename _Tp2>
344 operator!=(
const shared_ptr<_Tp1>& __a,
345 const shared_ptr<_Tp2>& __b) noexcept
346 {
return __a.get() != __b.get(); }
348 template<
typename _Tp>
350 operator!=(
const shared_ptr<_Tp>& __a, nullptr_t) noexcept
351 {
return (
bool)__a; }
353 template<
typename _Tp>
355 operator!=(nullptr_t,
const shared_ptr<_Tp>& __a) noexcept
356 {
return (
bool)__a; }
358 template<
typename _Tp1,
typename _Tp2>
360 operator<(const shared_ptr<_Tp1>& __a,
361 const shared_ptr<_Tp2>& __b) noexcept
367 template<
typename _Tp>
369 operator<(const shared_ptr<_Tp>& __a, nullptr_t) noexcept
372 template<
typename _Tp>
374 operator<(nullptr_t, const shared_ptr<_Tp>& __a) noexcept
377 template<
typename _Tp1,
typename _Tp2>
379 operator<=(const shared_ptr<_Tp1>& __a,
380 const shared_ptr<_Tp2>& __b) noexcept
381 {
return !(__b < __a); }
383 template<
typename _Tp>
385 operator<=(const shared_ptr<_Tp>& __a, nullptr_t) noexcept
386 {
return !(
nullptr < __a); }
388 template<
typename _Tp>
390 operator<=(nullptr_t, const shared_ptr<_Tp>& __a) noexcept
391 {
return !(__a <
nullptr); }
393 template<
typename _Tp1,
typename _Tp2>
395 operator>(
const shared_ptr<_Tp1>& __a,
396 const shared_ptr<_Tp2>& __b) noexcept
397 {
return (__b < __a); }
399 template<
typename _Tp>
401 operator>(
const shared_ptr<_Tp>& __a, nullptr_t) noexcept
404 template<
typename _Tp>
406 operator>(nullptr_t,
const shared_ptr<_Tp>& __a) noexcept
409 template<
typename _Tp1,
typename _Tp2>
411 operator>=(
const shared_ptr<_Tp1>& __a,
412 const shared_ptr<_Tp2>& __b) noexcept
413 {
return !(__a < __b); }
415 template<
typename _Tp>
417 operator>=(
const shared_ptr<_Tp>& __a, nullptr_t) noexcept
418 {
return !(__a <
nullptr); }
420 template<
typename _Tp>
422 operator>=(nullptr_t,
const shared_ptr<_Tp>& __a) noexcept
423 {
return !(
nullptr < __a); }
425 template<
typename _Tp>
426 struct less<shared_ptr<_Tp>> :
public _Sp_less<shared_ptr<_Tp>>
430 template<
typename _Tp>
432 swap(shared_ptr<_Tp>& __a, shared_ptr<_Tp>& __b) noexcept
436 template<
typename _Tp,
typename _Tp1>
437 inline shared_ptr<_Tp>
438 static_pointer_cast(
const shared_ptr<_Tp1>& __r) noexcept
439 {
return shared_ptr<_Tp>(__r,
static_cast<_Tp*
>(__r.get())); }
441 template<
typename _Tp,
typename _Tp1>
442 inline shared_ptr<_Tp>
443 const_pointer_cast(
const shared_ptr<_Tp1>& __r) noexcept
444 {
return shared_ptr<_Tp>(__r,
const_cast<_Tp*
>(__r.get())); }
446 template<
typename _Tp,
typename _Tp1>
447 inline shared_ptr<_Tp>
448 dynamic_pointer_cast(
const shared_ptr<_Tp1>& __r) noexcept
450 if (_Tp* __p = dynamic_cast<_Tp*>(__r.get()))
451 return shared_ptr<_Tp>(__r, __p);
452 return shared_ptr<_Tp>();
461 template<
typename _Tp>
466 : __weak_ptr<_Tp>() { }
468 template<
typename _Tp1,
typename =
typename
471 : __weak_ptr<_Tp>(__r) { }
473 template<
typename _Tp1,
typename =
typename
476 : __weak_ptr<_Tp>(__r) { }
478 template<
typename _Tp1>
482 this->__weak_ptr<_Tp>::operator=(__r);
486 template<
typename _Tp1>
490 this->__weak_ptr<_Tp>::operator=(__r);
495 lock()
const noexcept
516 template<
typename _Tp>
523 template<
typename _Tp>
527 template<
typename _Tp>
529 :
public _Sp_owner_less<shared_ptr<_Tp>, weak_ptr<_Tp>>
533 template<
typename _Tp>
535 :
public _Sp_owner_less<weak_ptr<_Tp>, shared_ptr<_Tp>>
541 template<
typename _Tp>
561 shared_from_this()
const
565 template<
typename _Tp1>
567 _M_weak_assign(_Tp1* __p,
const __shared_count<>& __n)
const noexcept
568 { _M_weak_this._M_assign(__p, __n); }
570 template<
typename _Tp1>
572 __enable_shared_from_this_helper(
const __shared_count<>& __pn,
574 const _Tp1* __px) noexcept
577 __pe->_M_weak_assign(const_cast<_Tp1*>(__px), __pn);
594 template<
typename _Tp,
typename _Alloc,
typename... _Args>
599 std::forward<_Args>(__args)...);
609 template<
typename _Tp,
typename... _Args>
610 inline shared_ptr<_Tp>
613 typedef typename std::remove_const<_Tp>::type _Tp_nc;
615 std::forward<_Args>(__args)...);
619 template<
typename _Tp>
621 :
public __hash_base<size_t, shared_ptr<_Tp>>
630 _GLIBCXX_END_NAMESPACE_VERSION
633 #endif // _SHARED_PTR_H
The standard allocator, as per [20.4].
shared_ptr(_Tp1 *__p, _Deleter __d)
Construct a shared_ptr that owns the pointer __p and the deleter __d.
constexpr _Tp && forward(typename std::remove_reference< _Tp >::type &__t) noexcept
Forward an lvalue.
20.7.12.2 unique_ptr for single objects.
Template class basic_ostream.This is the base class for all output streams. It provides text formatti...
constexpr shared_ptr(nullptr_t __p) noexcept
Construct an empty 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.
Define a member typedef type only if a boolean constant is true.
A simple smart pointer providing strict ownership semantics.
One of the comparison functors.
shared_ptr(shared_ptr< _Tp1 > &&__r) noexcept
Move-constructs a shared_ptr instance from __r.
A smart pointer with reference-counted copy semantics.
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...
Exception possibly thrown by 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...
Base class allowing use of member function shared_from_this.
shared_ptr(nullptr_t __p, _Deleter __d)
Construct a shared_ptr that owns a null pointer and the deleter __d.
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, _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.
shared_ptr(_Tp1 *__p, _Deleter __d, _Alloc __a)
Construct a shared_ptr that owns the pointer __p and the deleter __d.
constexpr shared_ptr() noexcept
Construct an empty shared_ptr.
shared_ptr< _Tp > make_shared(_Args &&...__args)
Create an object that is owned by a shared_ptr.
Primary template owner_less.
_Del * get_deleter(const __shared_ptr< _Tp, _Lp > &__p) noexcept
2.2.3.10 shared_ptr get_deleter (experimental)
Primary class template hash.
shared_ptr(shared_ptr &&__r) noexcept
Move-constructs a shared_ptr instance from __r.
Partial specializations for pointer types.
A smart pointer with weak semantics.