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
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>
258 : __shared_ptr<_Tp>(std::move(__r)) { }
266 : __shared_ptr<_Tp>(__p) { }
270 template<typename _Tp1>
272 operator=(const
shared_ptr<_Tp1>& __r) noexcept
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));
297 operator=(shared_ptr<_Tp1>&& __r) noexcept
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>
320 friend shared_ptr<_Tp1>
325 template<
typename _Tp1,
typename _Tp2>
327 operator==(
const shared_ptr<_Tp1>& __a,
328 const shared_ptr<_Tp2>& __b) noexcept
329 {
return __a.get() == __b.get(); }
331 template<
typename _Tp>
333 operator==(
const shared_ptr<_Tp>& __a, nullptr_t) noexcept
336 template<
typename _Tp>
338 operator==(nullptr_t,
const shared_ptr<_Tp>& __a) noexcept
341 template<
typename _Tp1,
typename _Tp2>
343 operator!=(
const shared_ptr<_Tp1>& __a,
344 const shared_ptr<_Tp2>& __b) noexcept
345 {
return __a.get() != __b.get(); }
347 template<
typename _Tp>
349 operator!=(
const shared_ptr<_Tp>& __a, nullptr_t) noexcept
350 {
return (
bool)__a; }
352 template<
typename _Tp>
354 operator!=(nullptr_t,
const shared_ptr<_Tp>& __a) noexcept
355 {
return (
bool)__a; }
357 template<
typename _Tp1,
typename _Tp2>
359 operator<(const shared_ptr<_Tp1>& __a,
360 const shared_ptr<_Tp2>& __b) noexcept
362 typedef typename std::common_type<_Tp1*, _Tp2*>::type _CT;
366 template<
typename _Tp>
368 operator<(const shared_ptr<_Tp>& __a, nullptr_t) noexcept
371 template<
typename _Tp>
373 operator<(nullptr_t, const shared_ptr<_Tp>& __a) noexcept
376 template<
typename _Tp1,
typename _Tp2>
378 operator<=(const shared_ptr<_Tp1>& __a,
379 const shared_ptr<_Tp2>& __b) noexcept
380 {
return !(__b < __a); }
382 template<
typename _Tp>
384 operator<=(const shared_ptr<_Tp>& __a, nullptr_t) noexcept
385 {
return !(
nullptr < __a); }
387 template<
typename _Tp>
389 operator<=(nullptr_t, const shared_ptr<_Tp>& __a) noexcept
390 {
return !(__a <
nullptr); }
392 template<
typename _Tp1,
typename _Tp2>
394 operator>(
const shared_ptr<_Tp1>& __a,
395 const shared_ptr<_Tp2>& __b) noexcept
396 {
return (__b < __a); }
398 template<
typename _Tp>
400 operator>(
const shared_ptr<_Tp>& __a, nullptr_t) noexcept
403 template<
typename _Tp>
405 operator>(nullptr_t,
const shared_ptr<_Tp>& __a) noexcept
408 template<
typename _Tp1,
typename _Tp2>
410 operator>=(
const shared_ptr<_Tp1>& __a,
411 const shared_ptr<_Tp2>& __b) noexcept
412 {
return !(__a < __b); }
414 template<
typename _Tp>
416 operator>=(
const shared_ptr<_Tp>& __a, nullptr_t) noexcept
417 {
return !(__a <
nullptr); }
419 template<
typename _Tp>
421 operator>=(nullptr_t,
const shared_ptr<_Tp>& __a) noexcept
422 {
return !(
nullptr < __a); }
424 template<
typename _Tp>
425 struct less<shared_ptr<_Tp>> :
public _Sp_less<shared_ptr<_Tp>>
429 template<
typename _Tp>
431 swap(shared_ptr<_Tp>& __a, shared_ptr<_Tp>& __b) noexcept
435 template<
typename _Tp,
typename _Tp1>
436 inline shared_ptr<_Tp>
437 static_pointer_cast(
const shared_ptr<_Tp1>& __r) noexcept
438 {
return shared_ptr<_Tp>(__r,
static_cast<_Tp*
>(__r.get())); }
440 template<
typename _Tp,
typename _Tp1>
441 inline shared_ptr<_Tp>
442 const_pointer_cast(
const shared_ptr<_Tp1>& __r) noexcept
443 {
return shared_ptr<_Tp>(__r,
const_cast<_Tp*
>(__r.get())); }
445 template<
typename _Tp,
typename _Tp1>
446 inline shared_ptr<_Tp>
447 dynamic_pointer_cast(
const shared_ptr<_Tp1>& __r) noexcept
449 if (_Tp* __p = dynamic_cast<_Tp*>(__r.get()))
450 return shared_ptr<_Tp>(__r, __p);
451 return shared_ptr<_Tp>();
460 template<
typename _Tp>
465 : __weak_ptr<_Tp>() { }
467 template<
typename _Tp1,
typename =
typename
468 std::enable_if<std::is_convertible<_Tp1*, _Tp*>::value>::type>
470 : __weak_ptr<_Tp>(__r) { }
472 template<
typename _Tp1,
typename =
typename
473 std::enable_if<std::is_convertible<_Tp1*, _Tp*>::value>::type>
475 : __weak_ptr<_Tp>(__r) { }
477 template<
typename _Tp1>
481 this->__weak_ptr<_Tp>::operator=(__r);
485 template<
typename _Tp1>
489 this->__weak_ptr<_Tp>::operator=(__r);
494 lock()
const noexcept
515 template<
typename _Tp>
522 template<
typename _Tp>
526 template<
typename _Tp>
528 :
public _Sp_owner_less<shared_ptr<_Tp>, weak_ptr<_Tp>>
532 template<
typename _Tp>
534 :
public _Sp_owner_less<weak_ptr<_Tp>, shared_ptr<_Tp>>
540 template<
typename _Tp>
560 shared_from_this()
const
564 template<
typename _Tp1>
566 _M_weak_assign(_Tp1* __p,
const __shared_count<>& __n)
const noexcept
567 { _M_weak_this._M_assign(__p, __n); }
569 template<
typename _Tp1>
571 __enable_shared_from_this_helper(
const __shared_count<>& __pn,
573 const _Tp1* __px) noexcept
576 __pe->_M_weak_assign(const_cast<_Tp1*>(__px), __pn);
593 template<
typename _Tp,
typename _Alloc,
typename... _Args>
598 std::forward<_Args>(__args)...);
608 template<
typename _Tp,
typename... _Args>
609 inline shared_ptr<_Tp>
612 typedef typename std::remove_const<_Tp>::type _Tp_nc;
614 std::forward<_Args>(__args)...);
618 template<
typename _Tp>
620 :
public __hash_base<size_t, shared_ptr<_Tp>>
629 _GLIBCXX_END_NAMESPACE_VERSION
632 #endif // _SHARED_PTR_H
Exception possibly thrown by shared_ptr.
shared_ptr(nullptr_t __p, _Deleter __d, _Alloc __a)
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.
Base class allowing use of member function shared_from_this.
20.7.1.2 unique_ptr for single objects.
shared_ptr(_Tp1 *__p, _Deleter __d, _Alloc __a)
Construct a shared_ptr that owns the pointer __p and the deleter __d.
A smart pointer with weak 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...
Primary template owner_less.
shared_ptr< _Tp > allocate_shared(const _Alloc &__a, _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...
One of the comparison functors.
constexpr shared_ptr(nullptr_t __p) noexcept
Construct an empty shared_ptr.
_Del * get_deleter(const __shared_ptr< _Tp, _Lp > &__p) noexcept
20.7.2.2.10 shared_ptr get_deleter
constexpr _Tp && forward(typename std::remove_reference< _Tp >::type &__t) noexcept
Forward an lvalue.
shared_ptr(nullptr_t __p, _Deleter __d)
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(const shared_ptr< _Tp1 > &__r, _Tp *__p) noexcept
Constructs a shared_ptr instance that stores __p and shares ownership with __r.
The standard allocator, as per [20.4].
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 swap(function< _Res(_Args...)> &__x, function< _Res(_Args...)> &__y)
Swap the targets of two polymorphic function object wrappers.
shared_ptr(shared_ptr< _Tp1 > &&__r) noexcept
Move-constructs a shared_ptr instance from __r.
Partial specializations for pointer types.
Template class basic_ostream.
shared_ptr(shared_ptr &&__r) noexcept
Move-constructs a shared_ptr instance from __r.
Primary class template hash.
A simple smart pointer providing strict ownership semantics.
constexpr shared_ptr() noexcept
Construct an empty shared_ptr.