1 // shared_ptr and weak_ptr implementation details -*- C++ -*-
3 // Copyright (C) 2007-2012 Free Software Foundation, Inc.
5 // This file is part of the GNU ISO C++ Library. This library is free
6 // software; you can redistribute it and/or modify it under the
7 // terms of the GNU General Public License as published by the
8 // Free Software Foundation; either version 3, or (at your option)
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // Under Section 7 of GPL version 3, you are granted additional
17 // permissions described in the GCC Runtime Library Exception, version
18 // 3.1, as published by the Free Software Foundation.
20 // You should have received a copy of the GNU General Public License and
21 // a copy of the GCC Runtime Library Exception along with this program;
22 // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
23 // <http://www.gnu.org/licenses/>.
25 // GCC Note: Based on files from version 1.32.0 of the Boost library.
28 // Copyright (c) 2001, 2002, 2003 Peter Dimov and Multi Media Ltd.
31 // Copyright (C) 1998, 1999 Greg Colvin and Beman Dawes.
32 // Copyright (C) 2001, 2002, 2003 Peter Dimov
35 // Copyright (C) 2001, 2002, 2003 Peter Dimov
37 // enable_shared_from_this.hpp
38 // Copyright (C) 2002 Peter Dimov
40 // Distributed under the Boost Software License, Version 1.0. (See
41 // accompanying file LICENSE_1_0.txt or copy at
42 // http://www.boost.org/LICENSE_1_0.txt)
44 /** @file bits/shared_ptr_base.h
45 * This is an internal header file, included by other library headers.
46 * Do not attempt to use it directly. @headername{memory}
49 #ifndef _SHARED_PTR_BASE_H
50 #define _SHARED_PTR_BASE_H 1
52 namespace std
_GLIBCXX_VISIBILITY(default)
54 _GLIBCXX_BEGIN_NAMESPACE_VERSION
56 #if _GLIBCXX_USE_DEPRECATED
57 template<typename
> class auto_ptr
;
61 * @brief Exception possibly thrown by @c shared_ptr.
64 class bad_weak_ptr
: public std::exception
68 what() const noexcept
;
70 virtual ~bad_weak_ptr() noexcept
;
73 // Substitute for bad_weak_ptr object in the case of -fno-exceptions.
75 __throw_bad_weak_ptr()
84 using __gnu_cxx::_Lock_policy
;
85 using __gnu_cxx::__default_lock_policy
;
86 using __gnu_cxx::_S_single
;
87 using __gnu_cxx::_S_mutex
;
88 using __gnu_cxx::_S_atomic
;
90 // Empty helper class except when the template argument is _S_mutex.
91 template<_Lock_policy _Lp
>
95 // The atomic policy uses fully-fenced builtins, single doesn't care.
96 enum { _S_need_barriers
= 0 };
100 class _Mutex_base
<_S_mutex
>
101 : public __gnu_cxx::__mutex
104 // This policy is used when atomic builtins are not available.
105 // The replacement atomic operations might not have the necessary
107 enum { _S_need_barriers
= 1 };
110 template<_Lock_policy _Lp
= __default_lock_policy
>
111 class _Sp_counted_base
112 : public _Mutex_base
<_Lp
>
115 _Sp_counted_base() noexcept
116 : _M_use_count(1), _M_weak_count(1) { }
119 ~_Sp_counted_base() noexcept
122 // Called when _M_use_count drops to zero, to release the resources
125 _M_dispose() noexcept
= 0;
127 // Called when _M_weak_count drops to zero.
129 _M_destroy() noexcept
133 _M_get_deleter(const std::type_info
&) = 0;
137 { __gnu_cxx::__atomic_add_dispatch(&_M_use_count
, 1); }
143 _M_release() noexcept
145 // Be race-detector-friendly. For more info see bits/c++config.
146 _GLIBCXX_SYNCHRONIZATION_HAPPENS_BEFORE(&_M_use_count
);
147 if (__gnu_cxx::__exchange_and_add_dispatch(&_M_use_count
, -1) == 1)
149 _GLIBCXX_SYNCHRONIZATION_HAPPENS_AFTER(&_M_use_count
);
151 // There must be a memory barrier between dispose() and destroy()
152 // to ensure that the effects of dispose() are observed in the
153 // thread that runs destroy().
154 // See http://gcc.gnu.org/ml/libstdc++/2005-11/msg00136.html
155 if (_Mutex_base
<_Lp
>::_S_need_barriers
)
157 _GLIBCXX_READ_MEM_BARRIER
;
158 _GLIBCXX_WRITE_MEM_BARRIER
;
161 // Be race-detector-friendly. For more info see bits/c++config.
162 _GLIBCXX_SYNCHRONIZATION_HAPPENS_BEFORE(&_M_weak_count
);
163 if (__gnu_cxx::__exchange_and_add_dispatch(&_M_weak_count
,
166 _GLIBCXX_SYNCHRONIZATION_HAPPENS_AFTER(&_M_weak_count
);
173 _M_weak_add_ref() noexcept
174 { __gnu_cxx::__atomic_add_dispatch(&_M_weak_count
, 1); }
177 _M_weak_release() noexcept
179 // Be race-detector-friendly. For more info see bits/c++config.
180 _GLIBCXX_SYNCHRONIZATION_HAPPENS_BEFORE(&_M_weak_count
);
181 if (__gnu_cxx::__exchange_and_add_dispatch(&_M_weak_count
, -1) == 1)
183 _GLIBCXX_SYNCHRONIZATION_HAPPENS_AFTER(&_M_weak_count
);
184 if (_Mutex_base
<_Lp
>::_S_need_barriers
)
187 // destroy() must observe results of dispose()
188 _GLIBCXX_READ_MEM_BARRIER
;
189 _GLIBCXX_WRITE_MEM_BARRIER
;
196 _M_get_use_count() const noexcept
198 // No memory barrier is used here so there is no synchronization
199 // with other threads.
200 return __atomic_load_n(&_M_use_count
, __ATOMIC_RELAXED
);
204 _Sp_counted_base(_Sp_counted_base
const&) = delete;
205 _Sp_counted_base
& operator=(_Sp_counted_base
const&) = delete;
207 _Atomic_word _M_use_count
; // #shared
208 _Atomic_word _M_weak_count
; // #weak + (#shared != 0)
213 _Sp_counted_base
<_S_single
>::
216 if (__gnu_cxx::__exchange_and_add_dispatch(&_M_use_count
, 1) == 0)
219 __throw_bad_weak_ptr();
225 _Sp_counted_base
<_S_mutex
>::
228 __gnu_cxx::__scoped_lock
sentry(*this);
229 if (__gnu_cxx::__exchange_and_add_dispatch(&_M_use_count
, 1) == 0)
232 __throw_bad_weak_ptr();
238 _Sp_counted_base
<_S_atomic
>::
241 // Perform lock-free add-if-not-zero operation.
242 _Atomic_word __count
= _M_use_count
;
246 __throw_bad_weak_ptr();
247 // Replace the current counter value with the old value + 1, as
248 // long as it's not changed meanwhile.
250 while (!__atomic_compare_exchange_n(&_M_use_count
, &__count
, __count
+ 1,
251 true, __ATOMIC_ACQ_REL
,
256 // Forward declarations.
257 template<typename _Tp
, _Lock_policy _Lp
= __default_lock_policy
>
260 template<typename _Tp
, _Lock_policy _Lp
= __default_lock_policy
>
263 template<typename _Tp
, _Lock_policy _Lp
= __default_lock_policy
>
264 class __enable_shared_from_this
;
266 template<typename _Tp
>
269 template<typename _Tp
>
272 template<typename _Tp
>
275 template<typename _Tp
>
276 class enable_shared_from_this
;
278 template<_Lock_policy _Lp
= __default_lock_policy
>
281 template<_Lock_policy _Lp
= __default_lock_policy
>
282 class __shared_count
;
285 // Counted ptr with no deleter or allocator support
286 template<typename _Ptr
, _Lock_policy _Lp
>
287 class _Sp_counted_ptr final
: public _Sp_counted_base
<_Lp
>
291 _Sp_counted_ptr(_Ptr __p
)
295 _M_dispose() noexcept
299 _M_destroy() noexcept
303 _M_get_deleter(const std::type_info
&)
306 _Sp_counted_ptr(const _Sp_counted_ptr
&) = delete;
307 _Sp_counted_ptr
& operator=(const _Sp_counted_ptr
&) = delete;
310 _Ptr _M_ptr
; // copy constructor must not throw
315 _Sp_counted_ptr
<nullptr_t
, _S_single
>::_M_dispose() noexcept
{ }
319 _Sp_counted_ptr
<nullptr_t
, _S_mutex
>::_M_dispose() noexcept
{ }
323 _Sp_counted_ptr
<nullptr_t
, _S_atomic
>::_M_dispose() noexcept
{ }
325 // Support for custom deleter and/or allocator
326 template<typename _Ptr
, typename _Deleter
, typename _Alloc
, _Lock_policy _Lp
>
327 class _Sp_counted_deleter final
: public _Sp_counted_base
<_Lp
>
329 // Helper class that stores the Deleter and also acts as an allocator.
330 // Used to dispose of the owned pointer and the internal refcount
331 // Requires that copies of _Alloc can free each other's memory.
333 : public _Alloc
// copy constructor must not throw
335 _Deleter _M_del
; // copy constructor must not throw
336 _My_Deleter(_Deleter __d
, const _Alloc
& __a
)
337 : _Alloc(__a
), _M_del(__d
) { }
341 // __d(__p) must not throw.
342 _Sp_counted_deleter(_Ptr __p
, _Deleter __d
)
343 : _M_ptr(__p
), _M_del(__d
, _Alloc()) { }
345 // __d(__p) must not throw.
346 _Sp_counted_deleter(_Ptr __p
, _Deleter __d
, const _Alloc
& __a
)
347 : _M_ptr(__p
), _M_del(__d
, __a
) { }
349 ~_Sp_counted_deleter() noexcept
{ }
352 _M_dispose() noexcept
353 { _M_del
._M_del(_M_ptr
); }
356 _M_destroy() noexcept
358 typedef typename allocator_traits
<_Alloc
>::template
359 rebind_traits
<_Sp_counted_deleter
> _Alloc_traits
;
360 typename
_Alloc_traits::allocator_type
__a(_M_del
);
361 _Alloc_traits::destroy(__a
, this);
362 _Alloc_traits::deallocate(__a
, this, 1);
366 _M_get_deleter(const std::type_info
& __ti
)
369 return __ti
== typeid(_Deleter
) ? &_M_del
._M_del
: 0;
376 _Ptr _M_ptr
; // copy constructor must not throw
377 _My_Deleter _M_del
; // copy constructor must not throw
380 // helpers for make_shared / allocate_shared
382 struct _Sp_make_shared_tag
{ };
384 template<typename _Tp
, typename _Alloc
, _Lock_policy _Lp
>
385 class _Sp_counted_ptr_inplace final
: public _Sp_counted_base
<_Lp
>
387 // Helper class that stores the pointer and also acts as an allocator.
388 // Used to dispose of the owned pointer and the internal refcount
389 // Requires that copies of _Alloc can free each other's memory.
391 : public _Alloc
// copy constructor must not throw
393 _Impl(_Alloc __a
) : _Alloc(__a
), _M_ptr() { }
398 template<typename
... _Args
>
399 _Sp_counted_ptr_inplace(_Alloc __a
, _Args
&&... __args
)
400 : _M_impl(__a
), _M_storage()
402 _M_impl
._M_ptr
= static_cast<_Tp
*>(static_cast<void*>(&_M_storage
));
403 // _GLIBCXX_RESOLVE_LIB_DEFECTS
404 // 2070. allocate_shared should use allocator_traits<A>::construct
405 allocator_traits
<_Alloc
>::construct(__a
, _M_impl
._M_ptr
,
406 std::forward
<_Args
>(__args
)...); // might throw
409 ~_Sp_counted_ptr_inplace() noexcept
{ }
412 _M_dispose() noexcept
413 { allocator_traits
<_Alloc
>::destroy(_M_impl
, _M_impl
._M_ptr
); }
415 // Override because the allocator needs to know the dynamic type
417 _M_destroy() noexcept
419 typedef typename allocator_traits
<_Alloc
>::template
420 rebind_traits
<_Sp_counted_ptr_inplace
> _Alloc_traits
;
421 typename
_Alloc_traits::allocator_type
__a(_M_impl
);
422 _Alloc_traits::destroy(__a
, this);
423 _Alloc_traits::deallocate(__a
, this, 1);
426 // Sneaky trick so __shared_ptr can get the managed pointer
428 _M_get_deleter(const std::type_info
& __ti
) noexcept
431 return __ti
== typeid(_Sp_make_shared_tag
)
432 ? static_cast<void*>(&_M_storage
)
441 typename aligned_storage
<sizeof(_Tp
), alignment_of
<_Tp
>::value
>::type
445 template<_Lock_policy _Lp
>
449 constexpr __shared_count() noexcept
: _M_pi(0)
452 template<typename _Ptr
>
454 __shared_count(_Ptr __p
) : _M_pi(0)
458 _M_pi
= new _Sp_counted_ptr
<_Ptr
, _Lp
>(__p
);
463 __throw_exception_again
;
467 template<typename _Ptr
, typename _Deleter
>
468 __shared_count(_Ptr __p
, _Deleter __d
) : _M_pi(0)
470 // The allocator's value_type doesn't matter, will rebind it anyway.
471 typedef std::allocator
<int> _Alloc
;
472 typedef _Sp_counted_deleter
<_Ptr
, _Deleter
, _Alloc
, _Lp
> _Sp_cd_type
;
473 typedef typename allocator_traits
<_Alloc
>::template
474 rebind_traits
<_Sp_cd_type
> _Alloc_traits
;
475 typename
_Alloc_traits::allocator_type __a
;
476 _Sp_cd_type
* __mem
= 0;
479 __mem
= _Alloc_traits::allocate(__a
, 1);
480 _Alloc_traits::construct(__a
, __mem
, __p
, std::move(__d
));
485 __d(__p
); // Call _Deleter on __p.
487 _Alloc_traits::deallocate(__a
, __mem
, 1);
488 __throw_exception_again
;
492 template<typename _Ptr
, typename _Deleter
, typename _Alloc
>
493 __shared_count(_Ptr __p
, _Deleter __d
, _Alloc __a
) : _M_pi(0)
495 typedef _Sp_counted_deleter
<_Ptr
, _Deleter
, _Alloc
, _Lp
> _Sp_cd_type
;
496 typedef typename allocator_traits
<_Alloc
>::template
497 rebind_traits
<_Sp_cd_type
> _Alloc_traits
;
498 typename
_Alloc_traits::allocator_type
__a2(__a
);
499 _Sp_cd_type
* __mem
= 0;
502 __mem
= _Alloc_traits::allocate(__a2
, 1);
503 _Alloc_traits::construct(__a2
, __mem
,
504 __p
, std::move(__d
), std::move(__a
));
509 __d(__p
); // Call _Deleter on __p.
511 _Alloc_traits::deallocate(__a2
, __mem
, 1);
512 __throw_exception_again
;
516 template<typename _Tp
, typename _Alloc
, typename
... _Args
>
517 __shared_count(_Sp_make_shared_tag
, _Tp
*, const _Alloc
& __a
,
521 typedef _Sp_counted_ptr_inplace
<_Tp
, _Alloc
, _Lp
> _Sp_cp_type
;
522 typedef typename allocator_traits
<_Alloc
>::template
523 rebind_traits
<_Sp_cp_type
> _Alloc_traits
;
524 typename
_Alloc_traits::allocator_type
__a2(__a
);
525 _Sp_cp_type
* __mem
= _Alloc_traits::allocate(__a2
, 1);
528 _Alloc_traits::construct(__a2
, __mem
, std::move(__a
),
529 std::forward
<_Args
>(__args
)...);
534 _Alloc_traits::deallocate(__a2
, __mem
, 1);
535 __throw_exception_again
;
539 #if _GLIBCXX_USE_DEPRECATED
540 // Special case for auto_ptr<_Tp> to provide the strong guarantee.
541 template<typename _Tp
>
543 __shared_count(std::auto_ptr
<_Tp
>&& __r
);
546 // Special case for unique_ptr<_Tp,_Del> to provide the strong guarantee.
547 template<typename _Tp
, typename _Del
>
549 __shared_count(std::unique_ptr
<_Tp
, _Del
>&& __r
)
550 : _M_pi(_S_create_from_up(std::move(__r
)))
553 // Throw bad_weak_ptr when __r._M_get_use_count() == 0.
554 explicit __shared_count(const __weak_count
<_Lp
>& __r
);
556 ~__shared_count() noexcept
562 __shared_count(const __shared_count
& __r
) noexcept
566 _M_pi
->_M_add_ref_copy();
570 operator=(const __shared_count
& __r
) noexcept
572 _Sp_counted_base
<_Lp
>* __tmp
= __r
._M_pi
;
576 __tmp
->_M_add_ref_copy();
585 _M_swap(__shared_count
& __r
) noexcept
587 _Sp_counted_base
<_Lp
>* __tmp
= __r
._M_pi
;
593 _M_get_use_count() const noexcept
594 { return _M_pi
!= 0 ? _M_pi
->_M_get_use_count() : 0; }
597 _M_unique() const noexcept
598 { return this->_M_get_use_count() == 1; }
601 _M_get_deleter(const std::type_info
& __ti
) const noexcept
602 { return _M_pi
? _M_pi
->_M_get_deleter(__ti
) : 0; }
605 _M_less(const __shared_count
& __rhs
) const noexcept
606 { return std::less
<_Sp_counted_base
<_Lp
>*>()(this->_M_pi
, __rhs
._M_pi
); }
609 _M_less(const __weak_count
<_Lp
>& __rhs
) const noexcept
610 { return std::less
<_Sp_counted_base
<_Lp
>*>()(this->_M_pi
, __rhs
._M_pi
); }
612 // Friend function injected into enclosing namespace and found by ADL
614 operator==(const __shared_count
& __a
, const __shared_count
& __b
) noexcept
615 { return __a
._M_pi
== __b
._M_pi
; }
618 friend class __weak_count
<_Lp
>;
620 template<typename _Tp
, typename _Del
>
621 static _Sp_counted_base
<_Lp
>*
622 _S_create_from_up(std::unique_ptr
<_Tp
, _Del
>&& __r
,
623 typename
std::enable_if
<!std::is_reference
<_Del
>::value
>::type
* = 0)
625 return new _Sp_counted_deleter
<_Tp
*, _Del
, std::allocator
<_Tp
>,
626 _Lp
>(__r
.get(), __r
.get_deleter());
629 template<typename _Tp
, typename _Del
>
630 static _Sp_counted_base
<_Lp
>*
631 _S_create_from_up(std::unique_ptr
<_Tp
, _Del
>&& __r
,
632 typename
std::enable_if
<std::is_reference
<_Del
>::value
>::type
* = 0)
634 typedef typename
std::remove_reference
<_Del
>::type _Del1
;
635 typedef std::reference_wrapper
<_Del1
> _Del2
;
636 return new _Sp_counted_deleter
<_Tp
*, _Del2
, std::allocator
<_Tp
>,
637 _Lp
>(__r
.get(), std::ref(__r
.get_deleter()));
640 _Sp_counted_base
<_Lp
>* _M_pi
;
644 template<_Lock_policy _Lp
>
648 constexpr __weak_count() noexcept
: _M_pi(0)
651 __weak_count(const __shared_count
<_Lp
>& __r
) noexcept
655 _M_pi
->_M_weak_add_ref();
658 __weak_count(const __weak_count
<_Lp
>& __r
) noexcept
662 _M_pi
->_M_weak_add_ref();
665 ~__weak_count() noexcept
668 _M_pi
->_M_weak_release();
672 operator=(const __shared_count
<_Lp
>& __r
) noexcept
674 _Sp_counted_base
<_Lp
>* __tmp
= __r
._M_pi
;
676 __tmp
->_M_weak_add_ref();
678 _M_pi
->_M_weak_release();
684 operator=(const __weak_count
<_Lp
>& __r
) noexcept
686 _Sp_counted_base
<_Lp
>* __tmp
= __r
._M_pi
;
688 __tmp
->_M_weak_add_ref();
690 _M_pi
->_M_weak_release();
696 _M_swap(__weak_count
<_Lp
>& __r
) noexcept
698 _Sp_counted_base
<_Lp
>* __tmp
= __r
._M_pi
;
704 _M_get_use_count() const noexcept
705 { return _M_pi
!= 0 ? _M_pi
->_M_get_use_count() : 0; }
708 _M_less(const __weak_count
& __rhs
) const noexcept
709 { return std::less
<_Sp_counted_base
<_Lp
>*>()(this->_M_pi
, __rhs
._M_pi
); }
712 _M_less(const __shared_count
<_Lp
>& __rhs
) const noexcept
713 { return std::less
<_Sp_counted_base
<_Lp
>*>()(this->_M_pi
, __rhs
._M_pi
); }
715 // Friend function injected into enclosing namespace and found by ADL
717 operator==(const __weak_count
& __a
, const __weak_count
& __b
) noexcept
718 { return __a
._M_pi
== __b
._M_pi
; }
721 friend class __shared_count
<_Lp
>;
723 _Sp_counted_base
<_Lp
>* _M_pi
;
726 // Now that __weak_count is defined we can define this constructor:
727 template<_Lock_policy _Lp
>
728 inline __shared_count
<_Lp
>:: __shared_count(const __weak_count
<_Lp
>& __r
)
732 _M_pi
->_M_add_ref_lock();
734 __throw_bad_weak_ptr();
738 // Support for enable_shared_from_this.
740 // Friend of __enable_shared_from_this.
741 template<_Lock_policy _Lp
, typename _Tp1
, typename _Tp2
>
743 __enable_shared_from_this_helper(const __shared_count
<_Lp
>&,
744 const __enable_shared_from_this
<_Tp1
,
745 _Lp
>*, const _Tp2
*) noexcept
;
747 // Friend of enable_shared_from_this.
748 template<typename _Tp1
, typename _Tp2
>
750 __enable_shared_from_this_helper(const __shared_count
<>&,
751 const enable_shared_from_this
<_Tp1
>*,
752 const _Tp2
*) noexcept
;
754 template<_Lock_policy _Lp
>
756 __enable_shared_from_this_helper(const __shared_count
<_Lp
>&, ...) noexcept
760 template<typename _Tp
, _Lock_policy _Lp
>
764 typedef _Tp element_type
;
766 constexpr __shared_ptr() noexcept
767 : _M_ptr(0), _M_refcount()
770 template<typename _Tp1
>
771 explicit __shared_ptr(_Tp1
* __p
)
772 : _M_ptr(__p
), _M_refcount(__p
)
774 __glibcxx_function_requires(_ConvertibleConcept
<_Tp1
*, _Tp
*>)
775 static_assert( sizeof(_Tp1
) > 0, "incomplete type" );
776 __enable_shared_from_this_helper(_M_refcount
, __p
, __p
);
779 template<typename _Tp1
, typename _Deleter
>
780 __shared_ptr(_Tp1
* __p
, _Deleter __d
)
781 : _M_ptr(__p
), _M_refcount(__p
, __d
)
783 __glibcxx_function_requires(_ConvertibleConcept
<_Tp1
*, _Tp
*>)
784 // TODO requires _Deleter CopyConstructible and __d(__p) well-formed
785 __enable_shared_from_this_helper(_M_refcount
, __p
, __p
);
788 template<typename _Tp1
, typename _Deleter
, typename _Alloc
>
789 __shared_ptr(_Tp1
* __p
, _Deleter __d
, _Alloc __a
)
790 : _M_ptr(__p
), _M_refcount(__p
, __d
, std::move(__a
))
792 __glibcxx_function_requires(_ConvertibleConcept
<_Tp1
*, _Tp
*>)
793 // TODO requires _Deleter CopyConstructible and __d(__p) well-formed
794 __enable_shared_from_this_helper(_M_refcount
, __p
, __p
);
797 template<typename _Deleter
>
798 __shared_ptr(nullptr_t __p
, _Deleter __d
)
799 : _M_ptr(0), _M_refcount(__p
, __d
)
802 template<typename _Deleter
, typename _Alloc
>
803 __shared_ptr(nullptr_t __p
, _Deleter __d
, _Alloc __a
)
804 : _M_ptr(0), _M_refcount(__p
, __d
, std::move(__a
))
807 template<typename _Tp1
>
808 __shared_ptr(const __shared_ptr
<_Tp1
, _Lp
>& __r
, _Tp
* __p
) noexcept
809 : _M_ptr(__p
), _M_refcount(__r
._M_refcount
) // never throws
812 __shared_ptr(const __shared_ptr
&) noexcept
= default;
813 __shared_ptr
& operator=(const __shared_ptr
&) noexcept
= default;
814 ~__shared_ptr() = default;
816 template<typename _Tp1
, typename
= typename
817 std::enable_if
<std::is_convertible
<_Tp1
*, _Tp
*>::value
>::type
>
818 __shared_ptr(const __shared_ptr
<_Tp1
, _Lp
>& __r
) noexcept
819 : _M_ptr(__r
._M_ptr
), _M_refcount(__r
._M_refcount
)
822 __shared_ptr(__shared_ptr
&& __r
) noexcept
823 : _M_ptr(__r
._M_ptr
), _M_refcount()
825 _M_refcount
._M_swap(__r
._M_refcount
);
829 template<typename _Tp1
, typename
= typename
830 std::enable_if
<std::is_convertible
<_Tp1
*, _Tp
*>::value
>::type
>
831 __shared_ptr(__shared_ptr
<_Tp1
, _Lp
>&& __r
) noexcept
832 : _M_ptr(__r
._M_ptr
), _M_refcount()
834 _M_refcount
._M_swap(__r
._M_refcount
);
838 template<typename _Tp1
>
839 explicit __shared_ptr(const __weak_ptr
<_Tp1
, _Lp
>& __r
)
840 : _M_refcount(__r
._M_refcount
) // may throw
842 __glibcxx_function_requires(_ConvertibleConcept
<_Tp1
*, _Tp
*>)
844 // It is now safe to copy __r._M_ptr, as
845 // _M_refcount(__r._M_refcount) did not throw.
849 // If an exception is thrown this constructor has no effect.
850 template<typename _Tp1
, typename _Del
>
851 __shared_ptr(std::unique_ptr
<_Tp1
, _Del
>&& __r
)
852 : _M_ptr(__r
.get()), _M_refcount()
854 __glibcxx_function_requires(_ConvertibleConcept
<_Tp1
*, _Tp
*>)
855 _Tp1
* __tmp
= __r
.get();
856 _M_refcount
= __shared_count
<_Lp
>(std::move(__r
));
857 __enable_shared_from_this_helper(_M_refcount
, __tmp
, __tmp
);
860 #if _GLIBCXX_USE_DEPRECATED
861 // Postcondition: use_count() == 1 and __r.get() == 0
862 template<typename _Tp1
>
863 __shared_ptr(std::auto_ptr
<_Tp1
>&& __r
);
866 /* TODO: use delegating constructor */
867 constexpr __shared_ptr(nullptr_t
) noexcept
868 : _M_ptr(0), _M_refcount()
871 template<typename _Tp1
>
873 operator=(const __shared_ptr
<_Tp1
, _Lp
>& __r
) noexcept
876 _M_refcount
= __r
._M_refcount
; // __shared_count::op= doesn't throw
880 #if _GLIBCXX_USE_DEPRECATED
881 template<typename _Tp1
>
883 operator=(std::auto_ptr
<_Tp1
>&& __r
)
885 __shared_ptr(std::move(__r
)).swap(*this);
891 operator=(__shared_ptr
&& __r
) noexcept
893 __shared_ptr(std::move(__r
)).swap(*this);
899 operator=(__shared_ptr
<_Tp1
, _Lp
>&& __r
) noexcept
901 __shared_ptr(std::move(__r
)).swap(*this);
905 template<typename _Tp1
, typename _Del
>
907 operator=(std::unique_ptr
<_Tp1
, _Del
>&& __r
)
909 __shared_ptr(std::move(__r
)).swap(*this);
915 { __shared_ptr().swap(*this); }
917 template<typename _Tp1
>
919 reset(_Tp1
* __p
) // _Tp1 must be complete.
921 // Catch self-reset errors.
922 _GLIBCXX_DEBUG_ASSERT(__p
== 0 || __p
!= _M_ptr
);
923 __shared_ptr(__p
).swap(*this);
926 template<typename _Tp1
, typename _Deleter
>
928 reset(_Tp1
* __p
, _Deleter __d
)
929 { __shared_ptr(__p
, __d
).swap(*this); }
931 template<typename _Tp1
, typename _Deleter
, typename _Alloc
>
933 reset(_Tp1
* __p
, _Deleter __d
, _Alloc __a
)
934 { __shared_ptr(__p
, __d
, std::move(__a
)).swap(*this); }
936 // Allow class instantiation when _Tp is [cv-qual] void.
937 typename
std::add_lvalue_reference
<_Tp
>::type
938 operator*() const noexcept
940 _GLIBCXX_DEBUG_ASSERT(_M_ptr
!= 0);
945 operator->() const noexcept
947 _GLIBCXX_DEBUG_ASSERT(_M_ptr
!= 0);
955 explicit operator bool() const // never throws
956 { return _M_ptr
== 0 ? false : true; }
959 unique() const noexcept
960 { return _M_refcount
._M_unique(); }
963 use_count() const noexcept
964 { return _M_refcount
._M_get_use_count(); }
967 swap(__shared_ptr
<_Tp
, _Lp
>& __other
) noexcept
969 std::swap(_M_ptr
, __other
._M_ptr
);
970 _M_refcount
._M_swap(__other
._M_refcount
);
973 template<typename _Tp1
>
975 owner_before(__shared_ptr
<_Tp1
, _Lp
> const& __rhs
) const
976 { return _M_refcount
._M_less(__rhs
._M_refcount
); }
978 template<typename _Tp1
>
980 owner_before(__weak_ptr
<_Tp1
, _Lp
> const& __rhs
) const
981 { return _M_refcount
._M_less(__rhs
._M_refcount
); }
985 // This constructor is non-standard, it is used by allocate_shared.
986 template<typename _Alloc
, typename
... _Args
>
987 __shared_ptr(_Sp_make_shared_tag __tag
, const _Alloc
& __a
,
989 : _M_ptr(), _M_refcount(__tag
, (_Tp
*)0, __a
,
990 std::forward
<_Args
>(__args
)...)
992 // _M_ptr needs to point to the newly constructed object.
993 // This relies on _Sp_counted_ptr_inplace::_M_get_deleter.
994 void* __p
= _M_refcount
._M_get_deleter(typeid(__tag
));
995 _M_ptr
= static_cast<_Tp
*>(__p
);
996 __enable_shared_from_this_helper(_M_refcount
, _M_ptr
, _M_ptr
);
999 template<typename _Alloc
>
1002 void operator()(_Tp
* __ptr
)
1004 typedef allocator_traits
<_Alloc
> _Alloc_traits
;
1005 _Alloc_traits::destroy(_M_alloc
, __ptr
);
1006 _Alloc_traits::deallocate(_M_alloc
, __ptr
, 1);
1011 template<typename _Alloc
, typename
... _Args
>
1012 __shared_ptr(_Sp_make_shared_tag __tag
, const _Alloc
& __a
,
1014 : _M_ptr(), _M_refcount()
1016 typedef typename
_Alloc::template rebind
<_Tp
>::other _Alloc2
;
1017 _Deleter
<_Alloc2
> __del
= { _Alloc2(__a
) };
1018 typedef allocator_traits
<_Alloc2
> __traits
;
1019 _M_ptr
= __traits::allocate(__del
._M_alloc
, 1);
1022 // _GLIBCXX_RESOLVE_LIB_DEFECTS
1023 // 2070. allocate_shared should use allocator_traits<A>::construct
1024 __traits::construct(__del
._M_alloc
, _M_ptr
,
1025 std::forward
<_Args
>(__args
)...);
1029 __traits::deallocate(__del
._M_alloc
, _M_ptr
, 1);
1030 __throw_exception_again
;
1032 __shared_count
<_Lp
> __count(_M_ptr
, __del
, __del
._M_alloc
);
1033 _M_refcount
._M_swap(__count
);
1034 __enable_shared_from_this_helper(_M_refcount
, _M_ptr
, _M_ptr
);
1038 template<typename _Tp1
, _Lock_policy _Lp1
, typename _Alloc
,
1040 friend __shared_ptr
<_Tp1
, _Lp1
>
1041 __allocate_shared(const _Alloc
& __a
, _Args
&&... __args
);
1045 _M_get_deleter(const std::type_info
& __ti
) const noexcept
1046 { return _M_refcount
._M_get_deleter(__ti
); }
1048 template<typename _Tp1
, _Lock_policy _Lp1
> friend class __shared_ptr
;
1049 template<typename _Tp1
, _Lock_policy _Lp1
> friend class __weak_ptr
;
1051 template<typename _Del
, typename _Tp1
, _Lock_policy _Lp1
>
1052 friend _Del
* get_deleter(const __shared_ptr
<_Tp1
, _Lp1
>&) noexcept
;
1054 _Tp
* _M_ptr
; // Contained pointer.
1055 __shared_count
<_Lp
> _M_refcount
; // Reference counter.
1059 // 20.8.13.2.7 shared_ptr comparisons
1060 template<typename _Tp1
, typename _Tp2
, _Lock_policy _Lp
>
1062 operator==(const __shared_ptr
<_Tp1
, _Lp
>& __a
,
1063 const __shared_ptr
<_Tp2
, _Lp
>& __b
) noexcept
1064 { return __a
.get() == __b
.get(); }
1066 template<typename _Tp
, _Lock_policy _Lp
>
1068 operator==(const __shared_ptr
<_Tp
, _Lp
>& __a
, nullptr_t
) noexcept
1071 template<typename _Tp
, _Lock_policy _Lp
>
1073 operator==(nullptr_t
, const __shared_ptr
<_Tp
, _Lp
>& __a
) noexcept
1076 template<typename _Tp1
, typename _Tp2
, _Lock_policy _Lp
>
1078 operator!=(const __shared_ptr
<_Tp1
, _Lp
>& __a
,
1079 const __shared_ptr
<_Tp2
, _Lp
>& __b
) noexcept
1080 { return __a
.get() != __b
.get(); }
1082 template<typename _Tp
, _Lock_policy _Lp
>
1084 operator!=(const __shared_ptr
<_Tp
, _Lp
>& __a
, nullptr_t
) noexcept
1085 { return (bool)__a
; }
1087 template<typename _Tp
, _Lock_policy _Lp
>
1089 operator!=(nullptr_t
, const __shared_ptr
<_Tp
, _Lp
>& __a
) noexcept
1090 { return (bool)__a
; }
1092 template<typename _Tp1
, typename _Tp2
, _Lock_policy _Lp
>
1094 operator<(const __shared_ptr
<_Tp1
, _Lp
>& __a
,
1095 const __shared_ptr
<_Tp2
, _Lp
>& __b
) noexcept
1097 typedef typename
std::common_type
<_Tp1
*, _Tp2
*>::type _CT
;
1098 return std::less
<_CT
>()(__a
.get(), __b
.get());
1101 template<typename _Tp
, _Lock_policy _Lp
>
1103 operator<(const __shared_ptr
<_Tp
, _Lp
>& __a
, nullptr_t
) noexcept
1104 { return std::less
<_Tp
*>()(__a
.get(), nullptr); }
1106 template<typename _Tp
, _Lock_policy _Lp
>
1108 operator<(nullptr_t
, const __shared_ptr
<_Tp
, _Lp
>& __a
) noexcept
1109 { return std::less
<_Tp
*>()(nullptr, __a
.get()); }
1111 template<typename _Tp1
, typename _Tp2
, _Lock_policy _Lp
>
1113 operator<=(const __shared_ptr
<_Tp1
, _Lp
>& __a
,
1114 const __shared_ptr
<_Tp2
, _Lp
>& __b
) noexcept
1115 { return !(__b
< __a
); }
1117 template<typename _Tp
, _Lock_policy _Lp
>
1119 operator<=(const __shared_ptr
<_Tp
, _Lp
>& __a
, nullptr_t
) noexcept
1120 { return !(nullptr < __a
); }
1122 template<typename _Tp
, _Lock_policy _Lp
>
1124 operator<=(nullptr_t
, const __shared_ptr
<_Tp
, _Lp
>& __a
) noexcept
1125 { return !(__a
< nullptr); }
1127 template<typename _Tp1
, typename _Tp2
, _Lock_policy _Lp
>
1129 operator>(const __shared_ptr
<_Tp1
, _Lp
>& __a
,
1130 const __shared_ptr
<_Tp2
, _Lp
>& __b
) noexcept
1131 { return (__b
< __a
); }
1133 template<typename _Tp
, _Lock_policy _Lp
>
1135 operator>(const __shared_ptr
<_Tp
, _Lp
>& __a
, nullptr_t
) noexcept
1136 { return std::less
<_Tp
*>()(nullptr, __a
.get()); }
1138 template<typename _Tp
, _Lock_policy _Lp
>
1140 operator>(nullptr_t
, const __shared_ptr
<_Tp
, _Lp
>& __a
) noexcept
1141 { return std::less
<_Tp
*>()(__a
.get(), nullptr); }
1143 template<typename _Tp1
, typename _Tp2
, _Lock_policy _Lp
>
1145 operator>=(const __shared_ptr
<_Tp1
, _Lp
>& __a
,
1146 const __shared_ptr
<_Tp2
, _Lp
>& __b
) noexcept
1147 { return !(__a
< __b
); }
1149 template<typename _Tp
, _Lock_policy _Lp
>
1151 operator>=(const __shared_ptr
<_Tp
, _Lp
>& __a
, nullptr_t
) noexcept
1152 { return !(__a
< nullptr); }
1154 template<typename _Tp
, _Lock_policy _Lp
>
1156 operator>=(nullptr_t
, const __shared_ptr
<_Tp
, _Lp
>& __a
) noexcept
1157 { return !(nullptr < __a
); }
1159 template<typename _Sp
>
1160 struct _Sp_less
: public binary_function
<_Sp
, _Sp
, bool>
1163 operator()(const _Sp
& __lhs
, const _Sp
& __rhs
) const noexcept
1165 typedef typename
_Sp::element_type element_type
;
1166 return std::less
<element_type
*>()(__lhs
.get(), __rhs
.get());
1170 template<typename _Tp
, _Lock_policy _Lp
>
1171 struct less
<__shared_ptr
<_Tp
, _Lp
>>
1172 : public _Sp_less
<__shared_ptr
<_Tp
, _Lp
>>
1175 // 2.2.3.8 shared_ptr specialized algorithms.
1176 template<typename _Tp
, _Lock_policy _Lp
>
1178 swap(__shared_ptr
<_Tp
, _Lp
>& __a
, __shared_ptr
<_Tp
, _Lp
>& __b
) noexcept
1181 // 2.2.3.9 shared_ptr casts
1183 // The seemingly equivalent code:
1184 // shared_ptr<_Tp, _Lp>(static_cast<_Tp*>(__r.get()))
1185 // will eventually result in undefined behaviour, attempting to
1186 // delete the same object twice.
1187 /// static_pointer_cast
1188 template<typename _Tp
, typename _Tp1
, _Lock_policy _Lp
>
1189 inline __shared_ptr
<_Tp
, _Lp
>
1190 static_pointer_cast(const __shared_ptr
<_Tp1
, _Lp
>& __r
) noexcept
1191 { return __shared_ptr
<_Tp
, _Lp
>(__r
, static_cast<_Tp
*>(__r
.get())); }
1193 // The seemingly equivalent code:
1194 // shared_ptr<_Tp, _Lp>(const_cast<_Tp*>(__r.get()))
1195 // will eventually result in undefined behaviour, attempting to
1196 // delete the same object twice.
1197 /// const_pointer_cast
1198 template<typename _Tp
, typename _Tp1
, _Lock_policy _Lp
>
1199 inline __shared_ptr
<_Tp
, _Lp
>
1200 const_pointer_cast(const __shared_ptr
<_Tp1
, _Lp
>& __r
) noexcept
1201 { return __shared_ptr
<_Tp
, _Lp
>(__r
, const_cast<_Tp
*>(__r
.get())); }
1203 // The seemingly equivalent code:
1204 // shared_ptr<_Tp, _Lp>(dynamic_cast<_Tp*>(__r.get()))
1205 // will eventually result in undefined behaviour, attempting to
1206 // delete the same object twice.
1207 /// dynamic_pointer_cast
1208 template<typename _Tp
, typename _Tp1
, _Lock_policy _Lp
>
1209 inline __shared_ptr
<_Tp
, _Lp
>
1210 dynamic_pointer_cast(const __shared_ptr
<_Tp1
, _Lp
>& __r
) noexcept
1212 if (_Tp
* __p
= dynamic_cast<_Tp
*>(__r
.get()))
1213 return __shared_ptr
<_Tp
, _Lp
>(__r
, __p
);
1214 return __shared_ptr
<_Tp
, _Lp
>();
1218 template<typename _Tp
, _Lock_policy _Lp
>
1222 typedef _Tp element_type
;
1224 constexpr __weak_ptr() noexcept
1225 : _M_ptr(0), _M_refcount()
1228 __weak_ptr(const __weak_ptr
&) noexcept
= default;
1229 __weak_ptr
& operator=(const __weak_ptr
&) noexcept
= default;
1230 ~__weak_ptr() = default;
1232 // The "obvious" converting constructor implementation:
1234 // template<typename _Tp1>
1235 // __weak_ptr(const __weak_ptr<_Tp1, _Lp>& __r)
1236 // : _M_ptr(__r._M_ptr), _M_refcount(__r._M_refcount) // never throws
1239 // has a serious problem.
1241 // __r._M_ptr may already have been invalidated. The _M_ptr(__r._M_ptr)
1242 // conversion may require access to *__r._M_ptr (virtual inheritance).
1244 // It is not possible to avoid spurious access violations since
1245 // in multithreaded programs __r._M_ptr may be invalidated at any point.
1246 template<typename _Tp1
, typename
= typename
1247 std::enable_if
<std::is_convertible
<_Tp1
*, _Tp
*>::value
>::type
>
1248 __weak_ptr(const __weak_ptr
<_Tp1
, _Lp
>& __r
) noexcept
1249 : _M_refcount(__r
._M_refcount
)
1250 { _M_ptr
= __r
.lock().get(); }
1252 template<typename _Tp1
, typename
= typename
1253 std::enable_if
<std::is_convertible
<_Tp1
*, _Tp
*>::value
>::type
>
1254 __weak_ptr(const __shared_ptr
<_Tp1
, _Lp
>& __r
) noexcept
1255 : _M_ptr(__r
._M_ptr
), _M_refcount(__r
._M_refcount
)
1258 template<typename _Tp1
>
1260 operator=(const __weak_ptr
<_Tp1
, _Lp
>& __r
) noexcept
1262 _M_ptr
= __r
.lock().get();
1263 _M_refcount
= __r
._M_refcount
;
1267 template<typename _Tp1
>
1269 operator=(const __shared_ptr
<_Tp1
, _Lp
>& __r
) noexcept
1271 _M_ptr
= __r
._M_ptr
;
1272 _M_refcount
= __r
._M_refcount
;
1276 __shared_ptr
<_Tp
, _Lp
>
1277 lock() const noexcept
1280 // Optimization: avoid throw overhead.
1282 return __shared_ptr
<element_type
, _Lp
>();
1286 return __shared_ptr
<element_type
, _Lp
>(*this);
1288 __catch(const bad_weak_ptr
&)
1290 // Q: How can we get here?
1291 // A: Another thread may have invalidated r after the
1292 // use_count test above.
1293 return __shared_ptr
<element_type
, _Lp
>();
1297 // Optimization: avoid try/catch overhead when single threaded.
1298 return expired() ? __shared_ptr
<element_type
, _Lp
>()
1299 : __shared_ptr
<element_type
, _Lp
>(*this);
1305 use_count() const noexcept
1306 { return _M_refcount
._M_get_use_count(); }
1309 expired() const noexcept
1310 { return _M_refcount
._M_get_use_count() == 0; }
1312 template<typename _Tp1
>
1314 owner_before(const __shared_ptr
<_Tp1
, _Lp
>& __rhs
) const
1315 { return _M_refcount
._M_less(__rhs
._M_refcount
); }
1317 template<typename _Tp1
>
1319 owner_before(const __weak_ptr
<_Tp1
, _Lp
>& __rhs
) const
1320 { return _M_refcount
._M_less(__rhs
._M_refcount
); }
1324 { __weak_ptr().swap(*this); }
1327 swap(__weak_ptr
& __s
) noexcept
1329 std::swap(_M_ptr
, __s
._M_ptr
);
1330 _M_refcount
._M_swap(__s
._M_refcount
);
1334 // Used by __enable_shared_from_this.
1336 _M_assign(_Tp
* __ptr
, const __shared_count
<_Lp
>& __refcount
) noexcept
1339 _M_refcount
= __refcount
;
1342 template<typename _Tp1
, _Lock_policy _Lp1
> friend class __shared_ptr
;
1343 template<typename _Tp1
, _Lock_policy _Lp1
> friend class __weak_ptr
;
1344 friend class __enable_shared_from_this
<_Tp
, _Lp
>;
1345 friend class enable_shared_from_this
<_Tp
>;
1347 _Tp
* _M_ptr
; // Contained pointer.
1348 __weak_count
<_Lp
> _M_refcount
; // Reference counter.
1351 // 20.8.13.3.7 weak_ptr specialized algorithms.
1352 template<typename _Tp
, _Lock_policy _Lp
>
1354 swap(__weak_ptr
<_Tp
, _Lp
>& __a
, __weak_ptr
<_Tp
, _Lp
>& __b
) noexcept
1357 template<typename _Tp
, typename _Tp1
>
1358 struct _Sp_owner_less
: public binary_function
<_Tp
, _Tp
, bool>
1361 operator()(const _Tp
& __lhs
, const _Tp
& __rhs
) const
1362 { return __lhs
.owner_before(__rhs
); }
1365 operator()(const _Tp
& __lhs
, const _Tp1
& __rhs
) const
1366 { return __lhs
.owner_before(__rhs
); }
1369 operator()(const _Tp1
& __lhs
, const _Tp
& __rhs
) const
1370 { return __lhs
.owner_before(__rhs
); }
1373 template<typename _Tp
, _Lock_policy _Lp
>
1374 struct owner_less
<__shared_ptr
<_Tp
, _Lp
>>
1375 : public _Sp_owner_less
<__shared_ptr
<_Tp
, _Lp
>, __weak_ptr
<_Tp
, _Lp
>>
1378 template<typename _Tp
, _Lock_policy _Lp
>
1379 struct owner_less
<__weak_ptr
<_Tp
, _Lp
>>
1380 : public _Sp_owner_less
<__weak_ptr
<_Tp
, _Lp
>, __shared_ptr
<_Tp
, _Lp
>>
1384 template<typename _Tp
, _Lock_policy _Lp
>
1385 class __enable_shared_from_this
1388 constexpr __enable_shared_from_this() noexcept
{ }
1390 __enable_shared_from_this(const __enable_shared_from_this
&) noexcept
{ }
1392 __enable_shared_from_this
&
1393 operator=(const __enable_shared_from_this
&) noexcept
1396 ~__enable_shared_from_this() { }
1399 __shared_ptr
<_Tp
, _Lp
>
1401 { return __shared_ptr
<_Tp
, _Lp
>(this->_M_weak_this
); }
1403 __shared_ptr
<const _Tp
, _Lp
>
1404 shared_from_this() const
1405 { return __shared_ptr
<const _Tp
, _Lp
>(this->_M_weak_this
); }
1408 template<typename _Tp1
>
1410 _M_weak_assign(_Tp1
* __p
, const __shared_count
<_Lp
>& __n
) const noexcept
1411 { _M_weak_this
._M_assign(__p
, __n
); }
1413 template<typename _Tp1
>
1415 __enable_shared_from_this_helper(const __shared_count
<_Lp
>& __pn
,
1416 const __enable_shared_from_this
* __pe
,
1417 const _Tp1
* __px
) noexcept
1420 __pe
->_M_weak_assign(const_cast<_Tp1
*>(__px
), __pn
);
1423 mutable __weak_ptr
<_Tp
, _Lp
> _M_weak_this
;
1427 template<typename _Tp
, _Lock_policy _Lp
, typename _Alloc
, typename
... _Args
>
1428 inline __shared_ptr
<_Tp
, _Lp
>
1429 __allocate_shared(const _Alloc
& __a
, _Args
&&... __args
)
1431 return __shared_ptr
<_Tp
, _Lp
>(_Sp_make_shared_tag(), __a
,
1432 std::forward
<_Args
>(__args
)...);
1435 template<typename _Tp
, _Lock_policy _Lp
, typename
... _Args
>
1436 inline __shared_ptr
<_Tp
, _Lp
>
1437 __make_shared(_Args
&&... __args
)
1439 typedef typename
std::remove_const
<_Tp
>::type _Tp_nc
;
1440 return std::__allocate_shared
<_Tp
, _Lp
>(std::allocator
<_Tp_nc
>(),
1441 std::forward
<_Args
>(__args
)...);
1444 /// std::hash specialization for __shared_ptr.
1445 template<typename _Tp
, _Lock_policy _Lp
>
1446 struct hash
<__shared_ptr
<_Tp
, _Lp
>>
1447 : public __hash_base
<size_t, __shared_ptr
<_Tp
, _Lp
>>
1450 operator()(const __shared_ptr
<_Tp
, _Lp
>& __s
) const noexcept
1451 { return std::hash
<_Tp
*>()(__s
.get()); }
1454 _GLIBCXX_END_NAMESPACE_VERSION
1457 #endif // _SHARED_PTR_BASE_H