libstdc++
shared_ptr.h
Go to the documentation of this file.
00001 // shared_ptr and weak_ptr implementation -*- C++ -*-
00002 
00003 // Copyright (C) 2007-2013 Free Software Foundation, Inc.
00004 //
00005 // This file is part of the GNU ISO C++ Library.  This library is free
00006 // software; you can redistribute it and/or modify it under the
00007 // terms of the GNU General Public License as published by the
00008 // Free Software Foundation; either version 3, or (at your option)
00009 // any later version.
00010 
00011 // This library is distributed in the hope that it will be useful,
00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014 // GNU General Public License for more details.
00015 
00016 // Under Section 7 of GPL version 3, you are granted additional
00017 // permissions described in the GCC Runtime Library Exception, version
00018 // 3.1, as published by the Free Software Foundation.
00019 
00020 // You should have received a copy of the GNU General Public License and
00021 // a copy of the GCC Runtime Library Exception along with this program;
00022 // see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
00023 // <http://www.gnu.org/licenses/>.
00024 
00025 // GCC Note: Based on files from version 1.32.0 of the Boost library.
00026 
00027 //  shared_count.hpp
00028 //  Copyright (c) 2001, 2002, 2003 Peter Dimov and Multi Media Ltd.
00029 
00030 //  shared_ptr.hpp
00031 //  Copyright (C) 1998, 1999 Greg Colvin and Beman Dawes.
00032 //  Copyright (C) 2001, 2002, 2003 Peter Dimov
00033 
00034 //  weak_ptr.hpp
00035 //  Copyright (C) 2001, 2002, 2003 Peter Dimov
00036 
00037 //  enable_shared_from_this.hpp
00038 //  Copyright (C) 2002 Peter Dimov
00039 
00040 // Distributed under the Boost Software License, Version 1.0. (See
00041 // accompanying file LICENSE_1_0.txt or copy at
00042 // http://www.boost.org/LICENSE_1_0.txt)
00043 
00044 /** @file bits/shared_ptr.h
00045  *  This is an internal header file, included by other library headers.
00046  *  Do not attempt to use it directly. @headername{memory}
00047  */
00048 
00049 #ifndef _SHARED_PTR_H
00050 #define _SHARED_PTR_H 1
00051 
00052 #include <bits/shared_ptr_base.h>
00053 
00054 namespace std _GLIBCXX_VISIBILITY(default)
00055 {
00056 _GLIBCXX_BEGIN_NAMESPACE_VERSION
00057 
00058   /**
00059    * @addtogroup pointer_abstractions
00060    * @{
00061    */
00062 
00063   /// 2.2.3.7 shared_ptr I/O
00064   template<typename _Ch, typename _Tr, typename _Tp, _Lock_policy _Lp>
00065     inline std::basic_ostream<_Ch, _Tr>&
00066     operator<<(std::basic_ostream<_Ch, _Tr>& __os,
00067            const __shared_ptr<_Tp, _Lp>& __p)
00068     {
00069       __os << __p.get();
00070       return __os;
00071     }
00072 
00073   /// 2.2.3.10 shared_ptr get_deleter (experimental)
00074   template<typename _Del, typename _Tp, _Lock_policy _Lp>
00075     inline _Del*
00076     get_deleter(const __shared_ptr<_Tp, _Lp>& __p) noexcept
00077     {
00078 #ifdef __GXX_RTTI
00079       return static_cast<_Del*>(__p._M_get_deleter(typeid(_Del)));
00080 #else
00081       return 0;
00082 #endif
00083     }
00084 
00085 
00086   /**
00087    *  @brief  A smart pointer with reference-counted copy semantics.
00088    *
00089    *  The object pointed to is deleted when the last shared_ptr pointing to
00090    *  it is destroyed or reset.
00091   */
00092   template<typename _Tp>
00093     class shared_ptr : public __shared_ptr<_Tp>
00094     {
00095     public:
00096       /**
00097        *  @brief  Construct an empty %shared_ptr.
00098        *  @post   use_count()==0 && get()==0
00099        */
00100       constexpr shared_ptr() noexcept
00101       : __shared_ptr<_Tp>() { }
00102 
00103       shared_ptr(const shared_ptr&) noexcept = default;
00104 
00105       /**
00106        *  @brief  Construct a %shared_ptr that owns the pointer @a __p.
00107        *  @param  __p  A pointer that is convertible to element_type*.
00108        *  @post   use_count() == 1 && get() == __p
00109        *  @throw  std::bad_alloc, in which case @c delete @a __p is called.
00110        */
00111       template<typename _Tp1>
00112     explicit shared_ptr(_Tp1* __p)
00113         : __shared_ptr<_Tp>(__p) { }
00114 
00115       /**
00116        *  @brief  Construct a %shared_ptr that owns the pointer @a __p
00117        *          and the deleter @a __d.
00118        *  @param  __p  A pointer.
00119        *  @param  __d  A deleter.
00120        *  @post   use_count() == 1 && get() == __p
00121        *  @throw  std::bad_alloc, in which case @a __d(__p) is called.
00122        *
00123        *  Requirements: _Deleter's copy constructor and destructor must
00124        *  not throw
00125        *
00126        *  __shared_ptr will release __p by calling __d(__p)
00127        */
00128       template<typename _Tp1, typename _Deleter>
00129     shared_ptr(_Tp1* __p, _Deleter __d)
00130         : __shared_ptr<_Tp>(__p, __d) { }
00131 
00132       /**
00133        *  @brief  Construct a %shared_ptr that owns a null pointer
00134        *          and the deleter @a __d.
00135        *  @param  __p  A null pointer constant.
00136        *  @param  __d  A deleter.
00137        *  @post   use_count() == 1 && get() == __p
00138        *  @throw  std::bad_alloc, in which case @a __d(__p) is called.
00139        *
00140        *  Requirements: _Deleter's copy constructor and destructor must
00141        *  not throw
00142        *
00143        *  The last owner will call __d(__p)
00144        */
00145       template<typename _Deleter>
00146     shared_ptr(nullptr_t __p, _Deleter __d)
00147         : __shared_ptr<_Tp>(__p, __d) { }
00148 
00149       /**
00150        *  @brief  Construct a %shared_ptr that owns the pointer @a __p
00151        *          and the deleter @a __d.
00152        *  @param  __p  A pointer.
00153        *  @param  __d  A deleter.
00154        *  @param  __a  An allocator.
00155        *  @post   use_count() == 1 && get() == __p
00156        *  @throw  std::bad_alloc, in which case @a __d(__p) is called.
00157        *
00158        *  Requirements: _Deleter's copy constructor and destructor must
00159        *  not throw _Alloc's copy constructor and destructor must not
00160        *  throw.
00161        *
00162        *  __shared_ptr will release __p by calling __d(__p)
00163        */
00164       template<typename _Tp1, typename _Deleter, typename _Alloc>
00165     shared_ptr(_Tp1* __p, _Deleter __d, _Alloc __a)
00166     : __shared_ptr<_Tp>(__p, __d, std::move(__a)) { }
00167 
00168       /**
00169        *  @brief  Construct a %shared_ptr that owns a null pointer
00170        *          and the deleter @a __d.
00171        *  @param  __p  A null pointer constant.
00172        *  @param  __d  A deleter.
00173        *  @param  __a  An allocator.
00174        *  @post   use_count() == 1 && get() == __p
00175        *  @throw  std::bad_alloc, in which case @a __d(__p) is called.
00176        *
00177        *  Requirements: _Deleter's copy constructor and destructor must
00178        *  not throw _Alloc's copy constructor and destructor must not
00179        *  throw.
00180        *
00181        *  The last owner will call __d(__p)
00182        */
00183       template<typename _Deleter, typename _Alloc>
00184     shared_ptr(nullptr_t __p, _Deleter __d, _Alloc __a)
00185     : __shared_ptr<_Tp>(__p, __d, std::move(__a)) { }
00186 
00187       // Aliasing constructor
00188 
00189       /**
00190        *  @brief  Constructs a %shared_ptr instance that stores @a __p
00191        *          and shares ownership with @a __r.
00192        *  @param  __r  A %shared_ptr.
00193        *  @param  __p  A pointer that will remain valid while @a *__r is valid.
00194        *  @post   get() == __p && use_count() == __r.use_count()
00195        *
00196        *  This can be used to construct a @c shared_ptr to a sub-object
00197        *  of an object managed by an existing @c shared_ptr.
00198        *
00199        * @code
00200        * shared_ptr< pair<int,int> > pii(new pair<int,int>());
00201        * shared_ptr<int> pi(pii, &pii->first);
00202        * assert(pii.use_count() == 2);
00203        * @endcode
00204        */
00205       template<typename _Tp1>
00206     shared_ptr(const shared_ptr<_Tp1>& __r, _Tp* __p) noexcept
00207     : __shared_ptr<_Tp>(__r, __p) { }
00208 
00209       /**
00210        *  @brief  If @a __r is empty, constructs an empty %shared_ptr;
00211        *          otherwise construct a %shared_ptr that shares ownership
00212        *          with @a __r.
00213        *  @param  __r  A %shared_ptr.
00214        *  @post   get() == __r.get() && use_count() == __r.use_count()
00215        */
00216       template<typename _Tp1, typename = typename
00217            std::enable_if<std::is_convertible<_Tp1*, _Tp*>::value>::type>
00218     shared_ptr(const shared_ptr<_Tp1>& __r) noexcept
00219         : __shared_ptr<_Tp>(__r) { }
00220 
00221       /**
00222        *  @brief  Move-constructs a %shared_ptr instance from @a __r.
00223        *  @param  __r  A %shared_ptr rvalue.
00224        *  @post   *this contains the old value of @a __r, @a __r is empty.
00225        */
00226       shared_ptr(shared_ptr&& __r) noexcept
00227       : __shared_ptr<_Tp>(std::move(__r)) { }
00228 
00229       /**
00230        *  @brief  Move-constructs a %shared_ptr instance from @a __r.
00231        *  @param  __r  A %shared_ptr rvalue.
00232        *  @post   *this contains the old value of @a __r, @a __r is empty.
00233        */
00234       template<typename _Tp1, typename = typename
00235            std::enable_if<std::is_convertible<_Tp1*, _Tp*>::value>::type>
00236     shared_ptr(shared_ptr<_Tp1>&& __r) noexcept
00237     : __shared_ptr<_Tp>(std::move(__r)) { }
00238 
00239       /**
00240        *  @brief  Constructs a %shared_ptr that shares ownership with @a __r
00241        *          and stores a copy of the pointer stored in @a __r.
00242        *  @param  __r  A weak_ptr.
00243        *  @post   use_count() == __r.use_count()
00244        *  @throw  bad_weak_ptr when __r.expired(),
00245        *          in which case the constructor has no effect.
00246        */
00247       template<typename _Tp1>
00248     explicit shared_ptr(const weak_ptr<_Tp1>& __r)
00249     : __shared_ptr<_Tp>(__r) { }
00250 
00251 #if _GLIBCXX_USE_DEPRECATED
00252       template<typename _Tp1>
00253     shared_ptr(std::auto_ptr<_Tp1>&& __r);
00254 #endif
00255 
00256       template<typename _Tp1, typename _Del>
00257     shared_ptr(std::unique_ptr<_Tp1, _Del>&& __r)
00258     : __shared_ptr<_Tp>(std::move(__r)) { }
00259 
00260       /**
00261        *  @brief  Construct an empty %shared_ptr.
00262        *  @param  __p  A null pointer constant.
00263        *  @post   use_count() == 0 && get() == nullptr
00264        */
00265       constexpr shared_ptr(nullptr_t __p) noexcept
00266       : __shared_ptr<_Tp>(__p) { }
00267 
00268       shared_ptr& operator=(const shared_ptr&) noexcept = default;
00269 
00270       template<typename _Tp1>
00271     shared_ptr&
00272     operator=(const shared_ptr<_Tp1>& __r) noexcept
00273     {
00274       this->__shared_ptr<_Tp>::operator=(__r);
00275       return *this;
00276     }
00277 
00278 #if _GLIBCXX_USE_DEPRECATED
00279       template<typename _Tp1>
00280     shared_ptr&
00281     operator=(std::auto_ptr<_Tp1>&& __r)
00282     {
00283       this->__shared_ptr<_Tp>::operator=(std::move(__r));
00284       return *this;
00285     }
00286 #endif
00287 
00288       shared_ptr&
00289       operator=(shared_ptr&& __r) noexcept
00290       {
00291     this->__shared_ptr<_Tp>::operator=(std::move(__r));
00292     return *this;
00293       }
00294 
00295       template<class _Tp1>
00296     shared_ptr&
00297     operator=(shared_ptr<_Tp1>&& __r) noexcept
00298     {
00299       this->__shared_ptr<_Tp>::operator=(std::move(__r));
00300       return *this;
00301     }
00302 
00303       template<typename _Tp1, typename _Del>
00304     shared_ptr&
00305     operator=(std::unique_ptr<_Tp1, _Del>&& __r)
00306     {
00307       this->__shared_ptr<_Tp>::operator=(std::move(__r));
00308       return *this;
00309     }
00310 
00311     private:
00312       // This constructor is non-standard, it is used by allocate_shared.
00313       template<typename _Alloc, typename... _Args>
00314     shared_ptr(_Sp_make_shared_tag __tag, const _Alloc& __a,
00315            _Args&&... __args)
00316     : __shared_ptr<_Tp>(__tag, __a, std::forward<_Args>(__args)...)
00317     { }
00318 
00319       template<typename _Tp1, typename _Alloc, typename... _Args>
00320     friend shared_ptr<_Tp1>
00321     allocate_shared(const _Alloc& __a, _Args&&... __args);
00322     };
00323 
00324   // 20.7.2.2.7 shared_ptr comparisons
00325   template<typename _Tp1, typename _Tp2>
00326     inline bool
00327     operator==(const shared_ptr<_Tp1>& __a,
00328            const shared_ptr<_Tp2>& __b) noexcept
00329     { return __a.get() == __b.get(); }
00330 
00331   template<typename _Tp>
00332     inline bool
00333     operator==(const shared_ptr<_Tp>& __a, nullptr_t) noexcept
00334     { return !__a; }
00335 
00336   template<typename _Tp>
00337     inline bool
00338     operator==(nullptr_t, const shared_ptr<_Tp>& __a) noexcept
00339     { return !__a; }
00340 
00341   template<typename _Tp1, typename _Tp2>
00342     inline bool
00343     operator!=(const shared_ptr<_Tp1>& __a,
00344            const shared_ptr<_Tp2>& __b) noexcept
00345     { return __a.get() != __b.get(); }
00346 
00347   template<typename _Tp>
00348     inline bool
00349     operator!=(const shared_ptr<_Tp>& __a, nullptr_t) noexcept
00350     { return (bool)__a; }
00351 
00352   template<typename _Tp>
00353     inline bool
00354     operator!=(nullptr_t, const shared_ptr<_Tp>& __a) noexcept
00355     { return (bool)__a; }
00356 
00357   template<typename _Tp1, typename _Tp2>
00358     inline bool
00359     operator<(const shared_ptr<_Tp1>& __a,
00360           const shared_ptr<_Tp2>& __b) noexcept
00361     {
00362       typedef typename std::common_type<_Tp1*, _Tp2*>::type _CT;
00363       return std::less<_CT>()(__a.get(), __b.get());
00364     }
00365 
00366   template<typename _Tp>
00367     inline bool
00368     operator<(const shared_ptr<_Tp>& __a, nullptr_t) noexcept
00369     { return std::less<_Tp*>()(__a.get(), nullptr); }
00370 
00371   template<typename _Tp>
00372     inline bool
00373     operator<(nullptr_t, const shared_ptr<_Tp>& __a) noexcept
00374     { return std::less<_Tp*>()(nullptr, __a.get()); }
00375 
00376   template<typename _Tp1, typename _Tp2>
00377     inline bool
00378     operator<=(const shared_ptr<_Tp1>& __a,
00379            const shared_ptr<_Tp2>& __b) noexcept
00380     { return !(__b < __a); }
00381 
00382   template<typename _Tp>
00383     inline bool
00384     operator<=(const shared_ptr<_Tp>& __a, nullptr_t) noexcept
00385     { return !(nullptr < __a); }
00386 
00387   template<typename _Tp>
00388     inline bool
00389     operator<=(nullptr_t, const shared_ptr<_Tp>& __a) noexcept
00390     { return !(__a < nullptr); }
00391 
00392   template<typename _Tp1, typename _Tp2>
00393     inline bool
00394     operator>(const shared_ptr<_Tp1>& __a,
00395           const shared_ptr<_Tp2>& __b) noexcept
00396     { return (__b < __a); }
00397 
00398   template<typename _Tp>
00399     inline bool
00400     operator>(const shared_ptr<_Tp>& __a, nullptr_t) noexcept
00401     { return std::less<_Tp*>()(nullptr, __a.get()); }
00402 
00403   template<typename _Tp>
00404     inline bool
00405     operator>(nullptr_t, const shared_ptr<_Tp>& __a) noexcept
00406     { return std::less<_Tp*>()(__a.get(), nullptr); }
00407 
00408   template<typename _Tp1, typename _Tp2>
00409     inline bool
00410     operator>=(const shared_ptr<_Tp1>& __a,
00411            const shared_ptr<_Tp2>& __b) noexcept
00412     { return !(__a < __b); }
00413 
00414   template<typename _Tp>
00415     inline bool
00416     operator>=(const shared_ptr<_Tp>& __a, nullptr_t) noexcept
00417     { return !(__a < nullptr); }
00418 
00419   template<typename _Tp>
00420     inline bool
00421     operator>=(nullptr_t, const shared_ptr<_Tp>& __a) noexcept
00422     { return !(nullptr < __a); }
00423 
00424   template<typename _Tp>
00425     struct less<shared_ptr<_Tp>> : public _Sp_less<shared_ptr<_Tp>>
00426     { };
00427 
00428   // 20.7.2.2.8 shared_ptr specialized algorithms.
00429   template<typename _Tp>
00430     inline void
00431     swap(shared_ptr<_Tp>& __a, shared_ptr<_Tp>& __b) noexcept
00432     { __a.swap(__b); }
00433 
00434   // 20.7.2.2.9 shared_ptr casts.
00435   template<typename _Tp, typename _Tp1>
00436     inline shared_ptr<_Tp>
00437     static_pointer_cast(const shared_ptr<_Tp1>& __r) noexcept
00438     { return shared_ptr<_Tp>(__r, static_cast<_Tp*>(__r.get())); }
00439 
00440   template<typename _Tp, typename _Tp1>
00441     inline shared_ptr<_Tp>
00442     const_pointer_cast(const shared_ptr<_Tp1>& __r) noexcept
00443     { return shared_ptr<_Tp>(__r, const_cast<_Tp*>(__r.get())); }
00444 
00445   template<typename _Tp, typename _Tp1>
00446     inline shared_ptr<_Tp>
00447     dynamic_pointer_cast(const shared_ptr<_Tp1>& __r) noexcept
00448     {
00449       if (_Tp* __p = dynamic_cast<_Tp*>(__r.get()))
00450     return shared_ptr<_Tp>(__r, __p);
00451       return shared_ptr<_Tp>();
00452     }
00453 
00454 
00455   /**
00456    *  @brief  A smart pointer with weak semantics.
00457    *
00458    *  With forwarding constructors and assignment operators.
00459    */
00460   template<typename _Tp>
00461     class weak_ptr : public __weak_ptr<_Tp>
00462     {
00463     public:
00464       constexpr weak_ptr() noexcept
00465       : __weak_ptr<_Tp>() { }
00466 
00467       template<typename _Tp1, typename = typename
00468            std::enable_if<std::is_convertible<_Tp1*, _Tp*>::value>::type>
00469     weak_ptr(const weak_ptr<_Tp1>& __r) noexcept
00470     : __weak_ptr<_Tp>(__r) { }
00471 
00472       template<typename _Tp1, typename = typename
00473            std::enable_if<std::is_convertible<_Tp1*, _Tp*>::value>::type>
00474     weak_ptr(const shared_ptr<_Tp1>& __r) noexcept
00475     : __weak_ptr<_Tp>(__r) { }
00476 
00477       template<typename _Tp1>
00478     weak_ptr&
00479     operator=(const weak_ptr<_Tp1>& __r) noexcept
00480     {
00481       this->__weak_ptr<_Tp>::operator=(__r);
00482       return *this;
00483     }
00484 
00485       template<typename _Tp1>
00486     weak_ptr&
00487     operator=(const shared_ptr<_Tp1>& __r) noexcept
00488     {
00489       this->__weak_ptr<_Tp>::operator=(__r);
00490       return *this;
00491     }
00492 
00493       shared_ptr<_Tp>
00494       lock() const noexcept
00495       {
00496 #ifdef __GTHREADS
00497     if (this->expired())
00498       return shared_ptr<_Tp>();
00499 
00500     __try
00501       {
00502         return shared_ptr<_Tp>(*this);
00503       }
00504     __catch(const bad_weak_ptr&)
00505       {
00506         return shared_ptr<_Tp>();
00507       }
00508 #else
00509     return this->expired() ? shared_ptr<_Tp>() : shared_ptr<_Tp>(*this);
00510 #endif
00511       }
00512     };
00513 
00514   // 20.7.2.3.6 weak_ptr specialized algorithms.
00515   template<typename _Tp>
00516     inline void
00517     swap(weak_ptr<_Tp>& __a, weak_ptr<_Tp>& __b) noexcept
00518     { __a.swap(__b); }
00519 
00520 
00521   /// Primary template owner_less
00522   template<typename _Tp>
00523     struct owner_less;
00524 
00525   /// Partial specialization of owner_less for shared_ptr.
00526   template<typename _Tp>
00527     struct owner_less<shared_ptr<_Tp>>
00528     : public _Sp_owner_less<shared_ptr<_Tp>, weak_ptr<_Tp>>
00529     { };
00530 
00531   /// Partial specialization of owner_less for weak_ptr.
00532   template<typename _Tp>
00533     struct owner_less<weak_ptr<_Tp>>
00534     : public _Sp_owner_less<weak_ptr<_Tp>, shared_ptr<_Tp>>
00535     { };
00536 
00537   /**
00538    *  @brief Base class allowing use of member function shared_from_this.
00539    */
00540   template<typename _Tp>
00541     class enable_shared_from_this
00542     {
00543     protected:
00544       constexpr enable_shared_from_this() noexcept { }
00545 
00546       enable_shared_from_this(const enable_shared_from_this&) noexcept { }
00547 
00548       enable_shared_from_this&
00549       operator=(const enable_shared_from_this&) noexcept
00550       { return *this; }
00551 
00552       ~enable_shared_from_this() { }
00553 
00554     public:
00555       shared_ptr<_Tp>
00556       shared_from_this()
00557       { return shared_ptr<_Tp>(this->_M_weak_this); }
00558 
00559       shared_ptr<const _Tp>
00560       shared_from_this() const
00561       { return shared_ptr<const _Tp>(this->_M_weak_this); }
00562 
00563     private:
00564       template<typename _Tp1>
00565     void
00566     _M_weak_assign(_Tp1* __p, const __shared_count<>& __n) const noexcept
00567     { _M_weak_this._M_assign(__p, __n); }
00568 
00569       template<typename _Tp1>
00570     friend void
00571     __enable_shared_from_this_helper(const __shared_count<>& __pn,
00572                      const enable_shared_from_this* __pe,
00573                      const _Tp1* __px) noexcept
00574     {
00575       if (__pe != 0)
00576         __pe->_M_weak_assign(const_cast<_Tp1*>(__px), __pn);
00577     }
00578 
00579       mutable weak_ptr<_Tp>  _M_weak_this;
00580     };
00581 
00582   /**
00583    *  @brief  Create an object that is owned by a shared_ptr.
00584    *  @param  __a     An allocator.
00585    *  @param  __args  Arguments for the @a _Tp object's constructor.
00586    *  @return A shared_ptr that owns the newly created object.
00587    *  @throw  An exception thrown from @a _Alloc::allocate or from the
00588    *          constructor of @a _Tp.
00589    *
00590    *  A copy of @a __a will be used to allocate memory for the shared_ptr
00591    *  and the new object.
00592    */
00593   template<typename _Tp, typename _Alloc, typename... _Args>
00594     inline shared_ptr<_Tp>
00595     allocate_shared(const _Alloc& __a, _Args&&... __args)
00596     {
00597       return shared_ptr<_Tp>(_Sp_make_shared_tag(), __a,
00598                  std::forward<_Args>(__args)...);
00599     }
00600 
00601   /**
00602    *  @brief  Create an object that is owned by a shared_ptr.
00603    *  @param  __args  Arguments for the @a _Tp object's constructor.
00604    *  @return A shared_ptr that owns the newly created object.
00605    *  @throw  std::bad_alloc, or an exception thrown from the
00606    *          constructor of @a _Tp.
00607    */
00608   template<typename _Tp, typename... _Args>
00609     inline shared_ptr<_Tp>
00610     make_shared(_Args&&... __args)
00611     {
00612       typedef typename std::remove_const<_Tp>::type _Tp_nc;
00613       return std::allocate_shared<_Tp>(std::allocator<_Tp_nc>(),
00614                        std::forward<_Args>(__args)...);
00615     }
00616 
00617   /// std::hash specialization for shared_ptr.
00618   template<typename _Tp>
00619     struct hash<shared_ptr<_Tp>>
00620     : public __hash_base<size_t, shared_ptr<_Tp>>
00621     {
00622       size_t
00623       operator()(const shared_ptr<_Tp>& __s) const noexcept
00624       { return std::hash<_Tp*>()(__s.get()); }
00625     };
00626 
00627   // @} group pointer_abstractions
00628 
00629 _GLIBCXX_END_NAMESPACE_VERSION
00630 } // namespace
00631 
00632 #endif // _SHARED_PTR_H