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>
65 inline std::basic_ostream<_Ch, _Tr>&
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 217 std::enable_if<std::is_convertible<_Tp1*, _Tp*>::value>::type>
219 : __shared_ptr<_Tp>(__r) { }
227 : __shared_ptr<_Tp>(
std::
move(__r)) { }
234 template<
typename _Tp1,
typename =
typename 235 std::enable_if<std::is_convertible<_Tp1*, _Tp*>::value>::type>
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>
256 template<
typename _Tp1,
typename _Del>
266 : __shared_ptr<_Tp>(__p) { }
270 template<
typename _Tp1>
274 this->__shared_ptr<_Tp>::operator=(__r);
278 #if _GLIBCXX_USE_DEPRECATED 279 template<
typename _Tp1>
283 this->__shared_ptr<_Tp>::operator=(
std::move(__r));
291 this->__shared_ptr<_Tp>::operator=(
std::move(__r));
299 this->__shared_ptr<_Tp>::operator=(
std::move(__r));
303 template<
typename _Tp1,
typename _Del>
307 this->__shared_ptr<_Tp>::operator=(
std::move(__r));
313 template<
typename _Alloc,
typename... _Args>
314 shared_ptr(_Sp_make_shared_tag __tag,
const _Alloc& __a,
316 : __shared_ptr<_Tp>(__tag, __a, std::forward<_Args>(__args)...)
319 template<
typename _Tp1,
typename _Alloc,
typename... _Args>
325 : __shared_ptr<_Tp>(__r, std::nothrow) { }
331 template<
typename _Tp1,
typename _Tp2>
335 {
return __a.get() == __b.get(); }
337 template<
typename _Tp>
342 template<
typename _Tp>
347 template<
typename _Tp1,
typename _Tp2>
351 {
return __a.get() != __b.get(); }
353 template<
typename _Tp>
356 {
return (
bool)__a; }
358 template<
typename _Tp>
361 {
return (
bool)__a; }
363 template<
typename _Tp1,
typename _Tp2>
365 operator<(const shared_ptr<_Tp1>& __a,
368 typedef typename std::common_type<_Tp1*, _Tp2*>::type _CT;
372 template<
typename _Tp>
374 operator<(const shared_ptr<_Tp>& __a, nullptr_t) noexcept
377 template<
typename _Tp>
379 operator<(nullptr_t, const shared_ptr<_Tp>& __a) noexcept
382 template<
typename _Tp1,
typename _Tp2>
384 operator<=(const shared_ptr<_Tp1>& __a,
386 {
return !(__b < __a); }
388 template<
typename _Tp>
390 operator<=(const shared_ptr<_Tp>& __a, nullptr_t) noexcept
391 {
return !(
nullptr < __a); }
393 template<
typename _Tp>
395 operator<=(nullptr_t, const shared_ptr<_Tp>& __a) noexcept
396 {
return !(__a <
nullptr); }
398 template<
typename _Tp1,
typename _Tp2>
402 {
return (__b < __a); }
404 template<
typename _Tp>
409 template<
typename _Tp>
414 template<
typename _Tp1,
typename _Tp2>
418 {
return !(__a < __b); }
420 template<
typename _Tp>
423 {
return !(__a <
nullptr); }
425 template<
typename _Tp>
428 {
return !(
nullptr < __a); }
430 template<
typename _Tp>
431 struct less<shared_ptr<_Tp>> :
public _Sp_less<shared_ptr<_Tp>>
435 template<
typename _Tp>
441 template<
typename _Tp,
typename _Tp1>
446 template<
typename _Tp,
typename _Tp1>
451 template<
typename _Tp,
typename _Tp1>
455 if (_Tp* __p = dynamic_cast<_Tp*>(__r.get()))
466 template<
typename _Tp>
471 : __weak_ptr<_Tp>() { }
473 template<
typename _Tp1,
typename =
typename 474 std::enable_if<std::is_convertible<_Tp1*, _Tp*>::value>::type>
476 : __weak_ptr<_Tp>(__r) { }
478 template<
typename _Tp1,
typename =
typename 479 std::enable_if<std::is_convertible<_Tp1*, _Tp*>::value>::type>
481 : __weak_ptr<_Tp>(__r) { }
483 template<
typename _Tp1>
487 this->__weak_ptr<_Tp>::operator=(__r);
491 template<
typename _Tp1>
495 this->__weak_ptr<_Tp>::operator=(__r);
500 lock()
const noexcept
505 template<
typename _Tp>
512 template<
typename _Tp>
516 template<
typename _Tp>
518 :
public _Sp_owner_less<shared_ptr<_Tp>, weak_ptr<_Tp>>
522 template<
typename _Tp>
524 :
public _Sp_owner_less<weak_ptr<_Tp>, shared_ptr<_Tp>>
530 template<
typename _Tp>
550 shared_from_this()
const 554 template<
typename _Tp1>
556 _M_weak_assign(_Tp1* __p,
const __shared_count<>& __n)
const noexcept
557 { _M_weak_this._M_assign(__p, __n); }
559 template<
typename _Tp1,
typename _Tp2>
561 __enable_shared_from_this_helper(
const __shared_count<>&,
563 const _Tp2*) noexcept;
568 template<
typename _Tp1,
typename _Tp2>
570 __enable_shared_from_this_helper(
const __shared_count<>& __pn,
572 __pe,
const _Tp2* __px) noexcept
575 __pe->_M_weak_assign(const_cast<_Tp2*>(__px), __pn);
589 template<
typename _Tp,
typename _Alloc,
typename... _Args>
594 std::forward<_Args>(__args)...);
604 template<
typename _Tp,
typename... _Args>
608 typedef typename std::remove_const<_Tp>::type _Tp_nc;
610 std::forward<_Args>(__args)...);
614 template<
typename _Tp>
616 :
public __hash_base<size_t, shared_ptr<_Tp>>
625 _GLIBCXX_END_NAMESPACE_VERSION
628 #endif // _SHARED_PTR_H shared_ptr(shared_ptr &&__r) noexcept
Move-constructs a shared_ptr instance from __r.
shared_ptr(nullptr_t __p, _Deleter __d, _Alloc __a)
Construct a shared_ptr that owns a null pointer and the deleter __d.
constexpr shared_ptr(nullptr_t __p) noexcept
Construct an empty shared_ptr.
constexpr shared_ptr() noexcept
Construct an empty shared_ptr.
bool operator>(const basic_string< _CharT, _Traits, _Alloc > &__lhs, const basic_string< _CharT, _Traits, _Alloc > &__rhs)
Test if string follows string.
void swap(_Tp &, _Tp &) noexcept(__and_< is_nothrow_move_constructible< _Tp >, is_nothrow_move_assignable< _Tp >>::value)
Swaps two values.
ISO C++ entities toplevel namespace is std.
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, _Alloc __a)
Construct a shared_ptr that owns the pointer __p and the deleter __d.
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...
A simple smart pointer providing strict ownership semantics.
Primary template owner_less.
A smart pointer with weak semantics.
_Del * get_deleter(const __shared_ptr< _Tp, _Lp > &__p) noexcept
20.7.2.2.10 shared_ptr get_deleter
Partial specializations for pointer types.
One of the comparison functors.
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.
Base class allowing use of member function shared_from_this.
constexpr std::remove_reference< _Tp >::type && move(_Tp &&__t) noexcept
Convert a value to an rvalue.
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.
bool operator>=(const basic_string< _CharT, _Traits, _Alloc > &__lhs, const basic_string< _CharT, _Traits, _Alloc > &__rhs)
Test if string doesn't precede string.
shared_ptr(const shared_ptr< _Tp1 > &__r, _Tp *__p) noexcept
Constructs a shared_ptr instance that stores __p and shares ownership with __r.
shared_ptr(_Tp1 *__p, _Deleter __d)
Construct a shared_ptr that owns the pointer __p and the deleter __d.
shared_ptr(shared_ptr< _Tp1 > &&__r) noexcept
Move-constructs a shared_ptr instance from __r.
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].
Primary class template hash.
A smart pointer with reference-counted copy semantics.