1 // shared_ptr and weak_ptr implementation -*- C++ -*-
3 // Copyright (C) 2007-2016 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)
45 * This is an internal header file, included by other library headers.
46 * Do not attempt to use it directly. @headername{memory}
50 #define _SHARED_PTR_H 1
52 #include <bits/shared_ptr_base.h>
54 namespace std
_GLIBCXX_VISIBILITY(default)
56 _GLIBCXX_BEGIN_NAMESPACE_VERSION
59 * @addtogroup pointer_abstractions
63 /// 20.7.2.2.11 shared_ptr I/O
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
)
73 /// 20.7.2.2.10 shared_ptr get_deleter
74 template<typename _Del
, typename _Tp
, _Lock_policy _Lp
>
76 get_deleter(const __shared_ptr
<_Tp
, _Lp
>& __p
) noexcept
79 return static_cast<_Del
*>(__p
._M_get_deleter(typeid(_Del
)));
87 * @brief A smart pointer with reference-counted copy semantics.
89 * The object pointed to is deleted when the last shared_ptr pointing to
90 * it is destroyed or reset.
92 template<typename _Tp
>
93 class shared_ptr
: public __shared_ptr
<_Tp
>
95 template<typename
... _Args
>
96 using _Constructible
= typename enable_if
<
97 is_constructible
<__shared_ptr
<_Tp
>, _Args
...>::value
100 template<typename _Arg
>
101 using _Assignable
= typename enable_if
<
102 is_assignable
<__shared_ptr
<_Tp
>&, _Arg
>::value
, shared_ptr
&
107 using element_type
= typename __shared_ptr
<_Tp
>::element_type
;
109 #if __cplusplus > 201402L
110 # define __cpp_lib_shared_ptr_weak_type 201606
111 using weak_type
= weak_ptr
<_Tp
>;
114 * @brief Construct an empty %shared_ptr.
115 * @post use_count()==0 && get()==0
117 constexpr shared_ptr() noexcept
: __shared_ptr
<_Tp
>() { }
119 shared_ptr(const shared_ptr
&) noexcept
= default;
122 * @brief Construct a %shared_ptr that owns the pointer @a __p.
123 * @param __p A pointer that is convertible to element_type*.
124 * @post use_count() == 1 && get() == __p
125 * @throw std::bad_alloc, in which case @c delete @a __p is called.
127 template<typename _Yp
, typename
= _Constructible
<_Yp
*>>
129 shared_ptr(_Yp
* __p
) : __shared_ptr
<_Tp
>(__p
) { }
132 * @brief Construct a %shared_ptr that owns the pointer @a __p
133 * and the deleter @a __d.
134 * @param __p A pointer.
135 * @param __d A deleter.
136 * @post use_count() == 1 && get() == __p
137 * @throw std::bad_alloc, in which case @a __d(__p) is called.
139 * Requirements: _Deleter's copy constructor and destructor must
142 * __shared_ptr will release __p by calling __d(__p)
144 template<typename _Yp
, typename _Deleter
,
145 typename
= _Constructible
<_Yp
*, _Deleter
>>
146 shared_ptr(_Yp
* __p
, _Deleter __d
)
147 : __shared_ptr
<_Tp
>(__p
, __d
) { }
150 * @brief Construct a %shared_ptr that owns a null pointer
151 * and the deleter @a __d.
152 * @param __p A null pointer constant.
153 * @param __d A deleter.
154 * @post use_count() == 1 && get() == __p
155 * @throw std::bad_alloc, in which case @a __d(__p) is called.
157 * Requirements: _Deleter's copy constructor and destructor must
160 * The last owner will call __d(__p)
162 template<typename _Deleter
>
163 shared_ptr(nullptr_t __p
, _Deleter __d
)
164 : __shared_ptr
<_Tp
>(__p
, __d
) { }
167 * @brief Construct a %shared_ptr that owns the pointer @a __p
168 * and the deleter @a __d.
169 * @param __p A pointer.
170 * @param __d A deleter.
171 * @param __a An allocator.
172 * @post use_count() == 1 && get() == __p
173 * @throw std::bad_alloc, in which case @a __d(__p) is called.
175 * Requirements: _Deleter's copy constructor and destructor must
176 * not throw _Alloc's copy constructor and destructor must not
179 * __shared_ptr will release __p by calling __d(__p)
181 template<typename _Yp
, typename _Deleter
, typename _Alloc
,
182 typename
= _Constructible
<_Yp
*, _Deleter
, _Alloc
>>
183 shared_ptr(_Yp
* __p
, _Deleter __d
, _Alloc __a
)
184 : __shared_ptr
<_Tp
>(__p
, __d
, std::move(__a
)) { }
187 * @brief Construct a %shared_ptr that owns a null pointer
188 * and the deleter @a __d.
189 * @param __p A null pointer constant.
190 * @param __d A deleter.
191 * @param __a An allocator.
192 * @post use_count() == 1 && get() == __p
193 * @throw std::bad_alloc, in which case @a __d(__p) is called.
195 * Requirements: _Deleter's copy constructor and destructor must
196 * not throw _Alloc's copy constructor and destructor must not
199 * The last owner will call __d(__p)
201 template<typename _Deleter
, typename _Alloc
>
202 shared_ptr(nullptr_t __p
, _Deleter __d
, _Alloc __a
)
203 : __shared_ptr
<_Tp
>(__p
, __d
, std::move(__a
)) { }
205 // Aliasing constructor
208 * @brief Constructs a %shared_ptr instance that stores @a __p
209 * and shares ownership with @a __r.
210 * @param __r A %shared_ptr.
211 * @param __p A pointer that will remain valid while @a *__r is valid.
212 * @post get() == __p && use_count() == __r.use_count()
214 * This can be used to construct a @c shared_ptr to a sub-object
215 * of an object managed by an existing @c shared_ptr.
218 * shared_ptr< pair<int,int> > pii(new pair<int,int>());
219 * shared_ptr<int> pi(pii, &pii->first);
220 * assert(pii.use_count() == 2);
223 template<typename _Yp
>
224 shared_ptr(const shared_ptr
<_Yp
>& __r
, element_type
* __p
) noexcept
225 : __shared_ptr
<_Tp
>(__r
, __p
) { }
228 * @brief If @a __r is empty, constructs an empty %shared_ptr;
229 * otherwise construct a %shared_ptr that shares ownership
231 * @param __r A %shared_ptr.
232 * @post get() == __r.get() && use_count() == __r.use_count()
234 template<typename _Yp
,
235 typename
= _Constructible
<const shared_ptr
<_Yp
>&>>
236 shared_ptr(const shared_ptr
<_Yp
>& __r
) noexcept
237 : __shared_ptr
<_Tp
>(__r
) { }
240 * @brief Move-constructs a %shared_ptr instance from @a __r.
241 * @param __r A %shared_ptr rvalue.
242 * @post *this contains the old value of @a __r, @a __r is empty.
244 shared_ptr(shared_ptr
&& __r
) noexcept
245 : __shared_ptr
<_Tp
>(std::move(__r
)) { }
248 * @brief Move-constructs a %shared_ptr instance from @a __r.
249 * @param __r A %shared_ptr rvalue.
250 * @post *this contains the old value of @a __r, @a __r is empty.
252 template<typename _Yp
, typename
= _Constructible
<shared_ptr
<_Yp
>>>
253 shared_ptr(shared_ptr
<_Yp
>&& __r
) noexcept
254 : __shared_ptr
<_Tp
>(std::move(__r
)) { }
257 * @brief Constructs a %shared_ptr that shares ownership with @a __r
258 * and stores a copy of the pointer stored in @a __r.
259 * @param __r A weak_ptr.
260 * @post use_count() == __r.use_count()
261 * @throw bad_weak_ptr when __r.expired(),
262 * in which case the constructor has no effect.
264 template<typename _Yp
, typename
= _Constructible
<const weak_ptr
<_Yp
>&>>
265 explicit shared_ptr(const weak_ptr
<_Yp
>& __r
)
266 : __shared_ptr
<_Tp
>(__r
) { }
268 #if _GLIBCXX_USE_DEPRECATED
269 template<typename _Yp
, typename
= _Constructible
<auto_ptr
<_Yp
>>>
270 shared_ptr(auto_ptr
<_Yp
>&& __r
);
273 // _GLIBCXX_RESOLVE_LIB_DEFECTS
274 // 2399. shared_ptr's constructor from unique_ptr should be constrained
275 template<typename _Yp
, typename _Del
,
276 typename
= _Constructible
<unique_ptr
<_Yp
, _Del
>>>
277 shared_ptr(unique_ptr
<_Yp
, _Del
>&& __r
)
278 : __shared_ptr
<_Tp
>(std::move(__r
)) { }
280 #if __cplusplus <= 201402L && _GLIBCXX_USE_DEPRECATED
281 // This non-standard constructor exists to support conversions that
282 // were possible in C++11 and C++14 but are ill-formed in C++17.
283 // If an exception is thrown this constructor has no effect.
284 template<typename _Yp
, typename _Del
,
285 _Constructible
<unique_ptr
<_Yp
, _Del
>, __sp_array_delete
>* = 0>
286 shared_ptr(unique_ptr
<_Yp
, _Del
>&& __r
)
287 : __shared_ptr
<_Tp
>(std::move(__r
), __sp_array_delete()) { }
291 * @brief Construct an empty %shared_ptr.
292 * @post use_count() == 0 && get() == nullptr
294 constexpr shared_ptr(nullptr_t
) noexcept
: shared_ptr() { }
296 shared_ptr
& operator=(const shared_ptr
&) noexcept
= default;
298 template<typename _Yp
>
299 _Assignable
<const shared_ptr
<_Yp
>&>
300 operator=(const shared_ptr
<_Yp
>& __r
) noexcept
302 this->__shared_ptr
<_Tp
>::operator=(__r
);
306 #if _GLIBCXX_USE_DEPRECATED
307 template<typename _Yp
>
308 _Assignable
<auto_ptr
<_Yp
>>
309 operator=(auto_ptr
<_Yp
>&& __r
)
311 this->__shared_ptr
<_Tp
>::operator=(std::move(__r
));
317 operator=(shared_ptr
&& __r
) noexcept
319 this->__shared_ptr
<_Tp
>::operator=(std::move(__r
));
324 _Assignable
<shared_ptr
<_Yp
>>
325 operator=(shared_ptr
<_Yp
>&& __r
) noexcept
327 this->__shared_ptr
<_Tp
>::operator=(std::move(__r
));
331 template<typename _Yp
, typename _Del
>
332 _Assignable
<unique_ptr
<_Yp
, _Del
>>
333 operator=(unique_ptr
<_Yp
, _Del
>&& __r
)
335 this->__shared_ptr
<_Tp
>::operator=(std::move(__r
));
340 // This constructor is non-standard, it is used by allocate_shared.
341 template<typename _Alloc
, typename
... _Args
>
342 shared_ptr(_Sp_make_shared_tag __tag
, const _Alloc
& __a
,
344 : __shared_ptr
<_Tp
>(__tag
, __a
, std::forward
<_Args
>(__args
)...)
347 template<typename _Yp
, typename _Alloc
, typename
... _Args
>
348 friend shared_ptr
<_Yp
>
349 allocate_shared(const _Alloc
& __a
, _Args
&&... __args
);
351 // This constructor is non-standard, it is used by weak_ptr::lock().
352 shared_ptr(const weak_ptr
<_Tp
>& __r
, std::nothrow_t
)
353 : __shared_ptr
<_Tp
>(__r
, std::nothrow
) { }
355 friend class weak_ptr
<_Tp
>;
358 // 20.7.2.2.7 shared_ptr comparisons
359 template<typename _Tp
, typename _Up
>
361 operator==(const shared_ptr
<_Tp
>& __a
, const shared_ptr
<_Up
>& __b
) noexcept
362 { return __a
.get() == __b
.get(); }
364 template<typename _Tp
>
366 operator==(const shared_ptr
<_Tp
>& __a
, nullptr_t
) noexcept
369 template<typename _Tp
>
371 operator==(nullptr_t
, const shared_ptr
<_Tp
>& __a
) noexcept
374 template<typename _Tp
, typename _Up
>
376 operator!=(const shared_ptr
<_Tp
>& __a
, const shared_ptr
<_Up
>& __b
) noexcept
377 { return __a
.get() != __b
.get(); }
379 template<typename _Tp
>
381 operator!=(const shared_ptr
<_Tp
>& __a
, nullptr_t
) noexcept
382 { return (bool)__a
; }
384 template<typename _Tp
>
386 operator!=(nullptr_t
, const shared_ptr
<_Tp
>& __a
) noexcept
387 { return (bool)__a
; }
389 template<typename _Tp
, typename _Up
>
391 operator<(const shared_ptr
<_Tp
>& __a
, const shared_ptr
<_Up
>& __b
) noexcept
393 using _Tp_elt
= typename shared_ptr
<_Tp
>::element_type
;
394 using _Up_elt
= typename shared_ptr
<_Up
>::element_type
;
395 using _Vp
= typename common_type
<_Tp_elt
*, _Up_elt
*>::type
;
396 return less
<_Vp
>()(__a
.get(), __b
.get());
399 template<typename _Tp
>
401 operator<(const shared_ptr
<_Tp
>& __a
, nullptr_t
) noexcept
403 using _Tp_elt
= typename shared_ptr
<_Tp
>::element_type
;
404 return less
<_Tp_elt
*>()(__a
.get(), nullptr);
407 template<typename _Tp
>
409 operator<(nullptr_t
, const shared_ptr
<_Tp
>& __a
) noexcept
411 using _Tp_elt
= typename shared_ptr
<_Tp
>::element_type
;
412 return less
<_Tp_elt
*>()(nullptr, __a
.get());
415 template<typename _Tp
, typename _Up
>
417 operator<=(const shared_ptr
<_Tp
>& __a
, const shared_ptr
<_Up
>& __b
) noexcept
418 { return !(__b
< __a
); }
420 template<typename _Tp
>
422 operator<=(const shared_ptr
<_Tp
>& __a
, nullptr_t
) noexcept
423 { return !(nullptr < __a
); }
425 template<typename _Tp
>
427 operator<=(nullptr_t
, const shared_ptr
<_Tp
>& __a
) noexcept
428 { return !(__a
< nullptr); }
430 template<typename _Tp
, typename _Up
>
432 operator>(const shared_ptr
<_Tp
>& __a
, const shared_ptr
<_Up
>& __b
) noexcept
433 { return (__b
< __a
); }
435 template<typename _Tp
>
437 operator>(const shared_ptr
<_Tp
>& __a
, nullptr_t
) noexcept
438 { return nullptr < __a
; }
440 template<typename _Tp
>
442 operator>(nullptr_t
, const shared_ptr
<_Tp
>& __a
) noexcept
443 { return __a
< nullptr; }
445 template<typename _Tp
, typename _Up
>
447 operator>=(const shared_ptr
<_Tp
>& __a
, const shared_ptr
<_Up
>& __b
) noexcept
448 { return !(__a
< __b
); }
450 template<typename _Tp
>
452 operator>=(const shared_ptr
<_Tp
>& __a
, nullptr_t
) noexcept
453 { return !(__a
< nullptr); }
455 template<typename _Tp
>
457 operator>=(nullptr_t
, const shared_ptr
<_Tp
>& __a
) noexcept
458 { return !(nullptr < __a
); }
460 template<typename _Tp
>
461 struct less
<shared_ptr
<_Tp
>> : public _Sp_less
<shared_ptr
<_Tp
>>
464 // 20.7.2.2.8 shared_ptr specialized algorithms.
465 template<typename _Tp
>
467 swap(shared_ptr
<_Tp
>& __a
, shared_ptr
<_Tp
>& __b
) noexcept
470 // 20.7.2.2.9 shared_ptr casts.
471 template<typename _Tp
, typename _Up
>
472 inline shared_ptr
<_Tp
>
473 static_pointer_cast(const shared_ptr
<_Up
>& __r
) noexcept
475 using _Sp
= shared_ptr
<_Tp
>;
476 return _Sp(__r
, static_cast<typename
_Sp::element_type
*>(__r
.get()));
479 template<typename _Tp
, typename _Up
>
480 inline shared_ptr
<_Tp
>
481 const_pointer_cast(const shared_ptr
<_Up
>& __r
) noexcept
483 using _Sp
= shared_ptr
<_Tp
>;
484 return _Sp(__r
, const_cast<typename
_Sp::element_type
*>(__r
.get()));
487 template<typename _Tp
, typename _Up
>
488 inline shared_ptr
<_Tp
>
489 dynamic_pointer_cast(const shared_ptr
<_Up
>& __r
) noexcept
491 using _Sp
= shared_ptr
<_Tp
>;
492 if (auto* __p
= dynamic_cast<typename
_Sp::element_type
*>(__r
.get()))
493 return _Sp(__r
, __p
);
497 #if __cplusplus > 201402L
498 template<typename _Tp
, typename _Up
>
499 inline shared_ptr
<_Tp
>
500 reinterpret_pointer_cast(const shared_ptr
<_Up
>& __r
) noexcept
502 using _Sp
= shared_ptr
<_Tp
>;
503 return _Sp(__r
, reinterpret_cast<typename
_Sp::element_type
*>(__r
.get()));
508 * @brief A smart pointer with weak semantics.
510 * With forwarding constructors and assignment operators.
512 template<typename _Tp
>
513 class weak_ptr
: public __weak_ptr
<_Tp
>
515 template<typename _Arg
>
516 using _Constructible
= typename enable_if
<
517 is_constructible
<__weak_ptr
<_Tp
>, _Arg
>::value
520 template<typename _Arg
>
521 using _Assignable
= typename enable_if
<
522 is_assignable
<__weak_ptr
<_Tp
>&, _Arg
>::value
, weak_ptr
&
526 constexpr weak_ptr() noexcept
= default;
528 template<typename _Yp
,
529 typename
= _Constructible
<const shared_ptr
<_Yp
>&>>
530 weak_ptr(const shared_ptr
<_Yp
>& __r
) noexcept
531 : __weak_ptr
<_Tp
>(__r
) { }
533 weak_ptr(const weak_ptr
&) noexcept
= default;
535 template<typename _Yp
, typename
= _Constructible
<const weak_ptr
<_Yp
>&>>
536 weak_ptr(const weak_ptr
<_Yp
>& __r
) noexcept
537 : __weak_ptr
<_Tp
>(__r
) { }
539 weak_ptr(weak_ptr
&&) noexcept
= default;
541 template<typename _Yp
, typename
= _Constructible
<weak_ptr
<_Yp
>>>
542 weak_ptr(weak_ptr
<_Yp
>&& __r
) noexcept
543 : __weak_ptr
<_Tp
>(std::move(__r
)) { }
546 operator=(const weak_ptr
& __r
) noexcept
= default;
548 template<typename _Yp
>
549 _Assignable
<const weak_ptr
<_Yp
>&>
550 operator=(const weak_ptr
<_Yp
>& __r
) noexcept
552 this->__weak_ptr
<_Tp
>::operator=(__r
);
556 template<typename _Yp
>
557 _Assignable
<const shared_ptr
<_Yp
>&>
558 operator=(const shared_ptr
<_Yp
>& __r
) noexcept
560 this->__weak_ptr
<_Tp
>::operator=(__r
);
565 operator=(weak_ptr
&& __r
) noexcept
= default;
567 template<typename _Yp
>
568 _Assignable
<weak_ptr
<_Yp
>>
569 operator=(weak_ptr
<_Yp
>&& __r
) noexcept
571 this->__weak_ptr
<_Tp
>::operator=(std::move(__r
));
576 lock() const noexcept
577 { return shared_ptr
<_Tp
>(*this, std::nothrow
); }
580 // 20.7.2.3.6 weak_ptr specialized algorithms.
581 template<typename _Tp
>
583 swap(weak_ptr
<_Tp
>& __a
, weak_ptr
<_Tp
>& __b
) noexcept
587 /// Primary template owner_less
588 template<typename _Tp
= void>
591 /// Void specialization of owner_less
593 struct owner_less
<void> : _Sp_owner_less
<void, void>
596 /// Partial specialization of owner_less for shared_ptr.
597 template<typename _Tp
>
598 struct owner_less
<shared_ptr
<_Tp
>>
599 : public _Sp_owner_less
<shared_ptr
<_Tp
>, weak_ptr
<_Tp
>>
602 /// Partial specialization of owner_less for weak_ptr.
603 template<typename _Tp
>
604 struct owner_less
<weak_ptr
<_Tp
>>
605 : public _Sp_owner_less
<weak_ptr
<_Tp
>, shared_ptr
<_Tp
>>
609 * @brief Base class allowing use of member function shared_from_this.
611 template<typename _Tp
>
612 class enable_shared_from_this
615 constexpr enable_shared_from_this() noexcept
{ }
617 enable_shared_from_this(const enable_shared_from_this
&) noexcept
{ }
619 enable_shared_from_this
&
620 operator=(const enable_shared_from_this
&) noexcept
623 ~enable_shared_from_this() { }
628 { return shared_ptr
<_Tp
>(this->_M_weak_this
); }
630 shared_ptr
<const _Tp
>
631 shared_from_this() const
632 { return shared_ptr
<const _Tp
>(this->_M_weak_this
); }
634 #if __cplusplus > 201402L || !defined(__STRICT_ANSI__) // c++1z or gnu++11
635 #define __cpp_lib_enable_shared_from_this 201603
637 weak_from_this() noexcept
638 { return this->_M_weak_this
; }
641 weak_from_this() const noexcept
642 { return this->_M_weak_this
; }
646 template<typename _Tp1
>
648 _M_weak_assign(_Tp1
* __p
, const __shared_count
<>& __n
) const noexcept
649 { _M_weak_this
._M_assign(__p
, __n
); }
651 // Found by ADL when this is an associated class.
652 friend const enable_shared_from_this
*
653 __enable_shared_from_this_base(const __shared_count
<>&,
654 const enable_shared_from_this
* __p
)
657 template<typename
, _Lock_policy
>
658 friend class __shared_ptr
;
660 mutable weak_ptr
<_Tp
> _M_weak_this
;
664 * @brief Create an object that is owned by a shared_ptr.
665 * @param __a An allocator.
666 * @param __args Arguments for the @a _Tp object's constructor.
667 * @return A shared_ptr that owns the newly created object.
668 * @throw An exception thrown from @a _Alloc::allocate or from the
669 * constructor of @a _Tp.
671 * A copy of @a __a will be used to allocate memory for the shared_ptr
672 * and the new object.
674 template<typename _Tp
, typename _Alloc
, typename
... _Args
>
675 inline shared_ptr
<_Tp
>
676 allocate_shared(const _Alloc
& __a
, _Args
&&... __args
)
678 return shared_ptr
<_Tp
>(_Sp_make_shared_tag(), __a
,
679 std::forward
<_Args
>(__args
)...);
683 * @brief Create an object that is owned by a shared_ptr.
684 * @param __args Arguments for the @a _Tp object's constructor.
685 * @return A shared_ptr that owns the newly created object.
686 * @throw std::bad_alloc, or an exception thrown from the
687 * constructor of @a _Tp.
689 template<typename _Tp
, typename
... _Args
>
690 inline shared_ptr
<_Tp
>
691 make_shared(_Args
&&... __args
)
693 typedef typename
std::remove_const
<_Tp
>::type _Tp_nc
;
694 return std::allocate_shared
<_Tp
>(std::allocator
<_Tp_nc
>(),
695 std::forward
<_Args
>(__args
)...);
698 /// std::hash specialization for shared_ptr.
699 template<typename _Tp
>
700 struct hash
<shared_ptr
<_Tp
>>
701 : public __hash_base
<size_t, shared_ptr
<_Tp
>>
704 operator()(const shared_ptr
<_Tp
>& __s
) const noexcept
706 return std::hash
<typename shared_ptr
<_Tp
>::element_type
*>()(__s
.get());
710 // @} group pointer_abstractions
712 _GLIBCXX_END_NAMESPACE_VERSION
715 #endif // _SHARED_PTR_H