1 #ifndef BOOST_SMART_PTR_SHARED_PTR_HPP_INCLUDED
2 #define BOOST_SMART_PTR_SHARED_PTR_HPP_INCLUDED
7 // (C) Copyright Greg Colvin and Beman Dawes 1998, 1999.
8 // Copyright (c) 2001-2008 Peter Dimov
10 // Distributed under the Boost Software License, Version 1.0. (See
11 // accompanying file LICENSE_1_0.txt or copy at
12 // http://www.boost.org/LICENSE_1_0.txt)
14 // See http://www.boost.org/libs/smart_ptr/shared_ptr.htm for documentation.
17 #include <boost/config.hpp> // for broken compiler workarounds
19 #if defined(BOOST_NO_MEMBER_TEMPLATES) && !defined(BOOST_MSVC6_MEMBER_TEMPLATES)
20 #include <boost/smart_ptr/detail/shared_ptr_nmt.hpp>
23 // In order to avoid circular dependencies with Boost.TR1
24 // we make sure that our include of <memory> doesn't try to
25 // pull in the TR1 headers: that's why we use this header
26 // rather than including <memory> directly:
27 #include <boost/config/no_tr1/memory.hpp> // std::auto_ptr
29 #include <boost/assert.hpp>
30 #include <boost/checked_delete.hpp>
31 #include <boost/throw_exception.hpp>
32 #include <boost/smart_ptr/detail/shared_count.hpp>
33 #include <boost/detail/workaround.hpp>
34 #include <boost/smart_ptr/detail/sp_convertible.hpp>
35 #include <boost/smart_ptr/detail/sp_nullptr_t.hpp>
37 #if !defined(BOOST_SP_NO_ATOMIC_ACCESS)
38 #include <boost/smart_ptr/detail/spinlock_pool.hpp>
39 #include <boost/memory_order.hpp>
42 #include <algorithm> // for std::swap
43 #include <functional> // for std::less
44 #include <typeinfo> // for std::bad_cast
45 #include <cstddef> // for std::size_t
47 #if !defined(BOOST_NO_IOSTREAM)
48 #if !defined(BOOST_NO_IOSFWD)
49 #include <iosfwd> // for std::basic_ostream
58 template<class T> class shared_ptr;
59 template<class T> class weak_ptr;
60 template<class T> class enable_shared_from_this;
61 class enable_shared_from_raw;
66 // sp_element, element_type
68 template< class T > struct sp_element
73 #if !defined( BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION )
75 template< class T > struct sp_element< T[] >
80 #if !defined( __BORLANDC__ ) || !BOOST_WORKAROUND( __BORLANDC__, < 0x600 )
82 template< class T, std::size_t N > struct sp_element< T[N] >
89 #endif // !defined( BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION )
91 // sp_dereference, return type of operator*
93 template< class T > struct sp_dereference
98 template<> struct sp_dereference< void >
103 #if !defined(BOOST_NO_CV_VOID_SPECIALIZATIONS)
105 template<> struct sp_dereference< void const >
110 template<> struct sp_dereference< void volatile >
115 template<> struct sp_dereference< void const volatile >
120 #endif // !defined(BOOST_NO_CV_VOID_SPECIALIZATIONS)
122 #if !defined( BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION )
124 template< class T > struct sp_dereference< T[] >
129 #if !defined( __BORLANDC__ ) || !BOOST_WORKAROUND( __BORLANDC__, < 0x600 )
131 template< class T, std::size_t N > struct sp_dereference< T[N] >
138 #endif // !defined( BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION )
140 // sp_member_access, return type of operator->
142 template< class T > struct sp_member_access
147 #if !defined( BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION )
149 template< class T > struct sp_member_access< T[] >
154 #if !defined( __BORLANDC__ ) || !BOOST_WORKAROUND( __BORLANDC__, < 0x600 )
156 template< class T, std::size_t N > struct sp_member_access< T[N] >
163 #endif // !defined( BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION )
165 // sp_array_access, return type of operator[]
167 template< class T > struct sp_array_access
172 #if !defined( BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION )
174 template< class T > struct sp_array_access< T[] >
179 #if !defined( __BORLANDC__ ) || !BOOST_WORKAROUND( __BORLANDC__, < 0x600 )
181 template< class T, std::size_t N > struct sp_array_access< T[N] >
188 #endif // !defined( BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION )
190 // sp_extent, for operator[] index check
192 template< class T > struct sp_extent
194 enum _vt { value = 0 };
197 #if !defined( BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION )
199 template< class T, std::size_t N > struct sp_extent< T[N] >
201 enum _vt { value = N };
204 #endif // !defined( BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION )
206 // enable_shared_from_this support
208 template< class X, class Y, class T > inline void sp_enable_shared_from_this( boost::shared_ptr<X> const * ppx, Y const * py, boost::enable_shared_from_this< T > const * pe )
212 pe->_internal_accept_owner( ppx, const_cast< Y* >( py ) );
216 template< class X, class Y > inline void sp_enable_shared_from_this( boost::shared_ptr<X> * ppx, Y const * py, boost::enable_shared_from_raw const * pe );
220 // Avoid C4793, ... causes native code generation
222 struct sp_any_pointer
224 template<class T> sp_any_pointer( T* ) {}
227 inline void sp_enable_shared_from_this( sp_any_pointer, sp_any_pointer, sp_any_pointer )
233 inline void sp_enable_shared_from_this( ... )
239 #if !defined( BOOST_NO_SFINAE ) && !defined( BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION ) && !defined( BOOST_NO_AUTO_PTR )
241 // rvalue auto_ptr support based on a technique by Dave Abrahams
243 template< class T, class R > struct sp_enable_if_auto_ptr
247 template< class T, class R > struct sp_enable_if_auto_ptr< std::auto_ptr< T >, R >
254 // sp_assert_convertible
256 template< class Y, class T > inline void sp_assert_convertible()
258 #if !defined( BOOST_SP_NO_SP_CONVERTIBLE )
260 // static_assert( sp_convertible< Y, T >::value );
261 typedef char tmp[ sp_convertible< Y, T >::value? 1: -1 ];
266 T* p = static_cast< Y* >( 0 );
272 // pointer constructor helper
274 template< class T, class Y > inline void sp_pointer_construct( boost::shared_ptr< T > * ppx, Y * p, boost::detail::shared_count & pn )
276 boost::detail::shared_count( p ).swap( pn );
277 boost::detail::sp_enable_shared_from_this( ppx, p, p );
280 #if !defined( BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION )
282 template< class T, class Y > inline void sp_pointer_construct( boost::shared_ptr< T[] > * /*ppx*/, Y * p, boost::detail::shared_count & pn )
284 sp_assert_convertible< Y[], T[] >();
285 boost::detail::shared_count( p, boost::checked_array_deleter< T >() ).swap( pn );
288 template< class T, std::size_t N, class Y > inline void sp_pointer_construct( boost::shared_ptr< T[N] > * /*ppx*/, Y * p, boost::detail::shared_count & pn )
290 sp_assert_convertible< Y[N], T[N] >();
291 boost::detail::shared_count( p, boost::checked_array_deleter< T >() ).swap( pn );
294 #endif // !defined( BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION )
296 // deleter constructor helper
298 template< class T, class Y > inline void sp_deleter_construct( boost::shared_ptr< T > * ppx, Y * p )
300 boost::detail::sp_enable_shared_from_this( ppx, p, p );
303 #if !defined( BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION )
305 template< class T, class Y > inline void sp_deleter_construct( boost::shared_ptr< T[] > * /*ppx*/, Y * /*p*/ )
307 sp_assert_convertible< Y[], T[] >();
310 template< class T, std::size_t N, class Y > inline void sp_deleter_construct( boost::shared_ptr< T[N] > * /*ppx*/, Y * /*p*/ )
312 sp_assert_convertible< Y[N], T[N] >();
315 #endif // !defined( BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION )
317 } // namespace detail
323 // An enhanced relative of scoped_ptr with reference counted copy semantics.
324 // The object pointed to is deleted when the last shared_ptr pointing to it
325 // is destroyed or reset.
328 template<class T> class shared_ptr
332 // Borland 5.5.1 specific workaround
333 typedef shared_ptr<T> this_type;
337 typedef typename boost::detail::sp_element< T >::type element_type;
339 shared_ptr() BOOST_NOEXCEPT : px( 0 ), pn() // never throws in 1.30+
343 #if !defined( BOOST_NO_CXX11_NULLPTR )
345 shared_ptr( boost::detail::sp_nullptr_t ) BOOST_NOEXCEPT : px( 0 ), pn() // never throws
352 explicit shared_ptr( Y * p ): px( p ), pn() // Y must be complete
354 boost::detail::sp_pointer_construct( this, p, pn );
358 // Requirements: D's copy constructor must not throw
360 // shared_ptr will release p by calling d(p)
363 template<class Y, class D> shared_ptr( Y * p, D d ): px( p ), pn( p, d )
365 boost::detail::sp_deleter_construct( this, p );
368 #if !defined( BOOST_NO_CXX11_NULLPTR )
370 template<class D> shared_ptr( boost::detail::sp_nullptr_t p, D d ): px( p ), pn( p, d )
376 // As above, but with allocator. A's copy constructor shall not throw.
378 template<class Y, class D, class A> shared_ptr( Y * p, D d, A a ): px( p ), pn( p, d, a )
380 boost::detail::sp_deleter_construct( this, p );
383 #if !defined( BOOST_NO_CXX11_NULLPTR )
385 template<class D, class A> shared_ptr( boost::detail::sp_nullptr_t p, D d, A a ): px( p ), pn( p, d, a )
391 // generated copy constructor, destructor are fine...
393 #if !defined( BOOST_NO_CXX11_RVALUE_REFERENCES )
395 // ... except in C++0x, move disables the implicit copy
397 shared_ptr( shared_ptr const & r ) BOOST_NOEXCEPT : px( r.px ), pn( r.pn )
404 explicit shared_ptr( weak_ptr<Y> const & r ): pn( r.pn ) // may throw
406 boost::detail::sp_assert_convertible< Y, T >();
408 // it is now safe to copy r.px, as pn(r.pn) did not throw
413 shared_ptr( weak_ptr<Y> const & r, boost::detail::sp_nothrow_tag )
414 BOOST_NOEXCEPT : px( 0 ), pn( r.pn, boost::detail::sp_nothrow_tag() )
423 #if !defined( BOOST_SP_NO_SP_CONVERTIBLE )
425 shared_ptr( shared_ptr<Y> const & r, typename boost::detail::sp_enable_if_convertible<Y,T>::type = boost::detail::sp_empty() )
429 shared_ptr( shared_ptr<Y> const & r )
432 BOOST_NOEXCEPT : px( r.px ), pn( r.pn )
434 boost::detail::sp_assert_convertible< Y, T >();
439 shared_ptr( shared_ptr<Y> const & r, element_type * p ) BOOST_NOEXCEPT : px( p ), pn( r.pn )
443 #ifndef BOOST_NO_AUTO_PTR
446 explicit shared_ptr( std::auto_ptr<Y> & r ): px(r.get()), pn()
448 boost::detail::sp_assert_convertible< Y, T >();
451 pn = boost::detail::shared_count( r );
453 boost::detail::sp_deleter_construct( this, tmp );
456 #if !defined( BOOST_NO_CXX11_RVALUE_REFERENCES )
459 shared_ptr( std::auto_ptr<Y> && r ): px(r.get()), pn()
461 boost::detail::sp_assert_convertible< Y, T >();
464 pn = boost::detail::shared_count( r );
466 boost::detail::sp_deleter_construct( this, tmp );
469 #elif !defined( BOOST_NO_SFINAE ) && !defined( BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION )
472 explicit shared_ptr( Ap r, typename boost::detail::sp_enable_if_auto_ptr<Ap, int>::type = 0 ): px( r.get() ), pn()
474 typedef typename Ap::element_type Y;
476 boost::detail::sp_assert_convertible< Y, T >();
479 pn = boost::detail::shared_count( r );
481 boost::detail::sp_deleter_construct( this, tmp );
484 #endif // BOOST_NO_SFINAE, BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
486 #endif // BOOST_NO_AUTO_PTR
488 #if !defined( BOOST_NO_CXX11_SMART_PTR ) && !defined( BOOST_NO_CXX11_RVALUE_REFERENCES )
490 template< class Y, class D >
491 shared_ptr( std::unique_ptr< Y, D > && r ): px( r.get() ), pn()
493 boost::detail::sp_assert_convertible< Y, T >();
495 typename std::unique_ptr< Y, D >::pointer tmp = r.get();
496 pn = boost::detail::shared_count( r );
498 boost::detail::sp_deleter_construct( this, tmp );
505 shared_ptr & operator=( shared_ptr const & r ) BOOST_NOEXCEPT
507 this_type(r).swap(*this);
511 #if !defined(BOOST_MSVC) || (BOOST_MSVC >= 1400)
514 shared_ptr & operator=(shared_ptr<Y> const & r) BOOST_NOEXCEPT
516 this_type(r).swap(*this);
522 #ifndef BOOST_NO_AUTO_PTR
525 shared_ptr & operator=( std::auto_ptr<Y> & r )
527 this_type( r ).swap( *this );
531 #if !defined( BOOST_NO_CXX11_RVALUE_REFERENCES )
534 shared_ptr & operator=( std::auto_ptr<Y> && r )
536 this_type( static_cast< std::auto_ptr<Y> && >( r ) ).swap( *this );
540 #elif !defined( BOOST_NO_SFINAE ) && !defined( BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION )
543 typename boost::detail::sp_enable_if_auto_ptr< Ap, shared_ptr & >::type operator=( Ap r )
545 this_type( r ).swap( *this );
549 #endif // BOOST_NO_SFINAE, BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
551 #endif // BOOST_NO_AUTO_PTR
553 #if !defined( BOOST_NO_CXX11_SMART_PTR ) && !defined( BOOST_NO_CXX11_RVALUE_REFERENCES )
555 template<class Y, class D>
556 shared_ptr & operator=( std::unique_ptr<Y, D> && r )
558 this_type( static_cast< std::unique_ptr<Y, D> && >( r ) ).swap(*this);
566 #if !defined( BOOST_NO_CXX11_RVALUE_REFERENCES )
568 shared_ptr( shared_ptr && r ) BOOST_NOEXCEPT : px( r.px ), pn()
575 #if !defined( BOOST_SP_NO_SP_CONVERTIBLE )
577 shared_ptr( shared_ptr<Y> && r, typename boost::detail::sp_enable_if_convertible<Y,T>::type = boost::detail::sp_empty() )
581 shared_ptr( shared_ptr<Y> && r )
584 BOOST_NOEXCEPT : px( r.px ), pn()
586 boost::detail::sp_assert_convertible< Y, T >();
592 shared_ptr & operator=( shared_ptr && r ) BOOST_NOEXCEPT
594 this_type( static_cast< shared_ptr && >( r ) ).swap( *this );
599 shared_ptr & operator=( shared_ptr<Y> && r ) BOOST_NOEXCEPT
601 this_type( static_cast< shared_ptr<Y> && >( r ) ).swap( *this );
607 #if !defined( BOOST_NO_CXX11_NULLPTR )
609 shared_ptr & operator=( boost::detail::sp_nullptr_t ) BOOST_NOEXCEPT // never throws
611 this_type().swap(*this);
617 void reset() BOOST_NOEXCEPT // never throws in 1.30+
619 this_type().swap(*this);
622 template<class Y> void reset( Y * p ) // Y must be complete
624 BOOST_ASSERT( p == 0 || p != px ); // catch self-reset errors
625 this_type( p ).swap( *this );
628 template<class Y, class D> void reset( Y * p, D d )
630 this_type( p, d ).swap( *this );
633 template<class Y, class D, class A> void reset( Y * p, D d, A a )
635 this_type( p, d, a ).swap( *this );
638 template<class Y> void reset( shared_ptr<Y> const & r, element_type * p )
640 this_type( r, p ).swap( *this );
643 // never throws (but has a BOOST_ASSERT in it, so not marked with BOOST_NOEXCEPT)
644 typename boost::detail::sp_dereference< T >::type operator* () const
646 BOOST_ASSERT( px != 0 );
650 // never throws (but has a BOOST_ASSERT in it, so not marked with BOOST_NOEXCEPT)
651 typename boost::detail::sp_member_access< T >::type operator-> () const
653 BOOST_ASSERT( px != 0 );
657 // never throws (but has a BOOST_ASSERT in it, so not marked with BOOST_NOEXCEPT)
658 typename boost::detail::sp_array_access< T >::type operator[] ( std::ptrdiff_t i ) const
660 BOOST_ASSERT( px != 0 );
661 BOOST_ASSERT( i >= 0 && ( i < boost::detail::sp_extent< T >::value || boost::detail::sp_extent< T >::value == 0 ) );
666 element_type * get() const BOOST_NOEXCEPT
671 // implicit conversion to "bool"
672 #include <boost/smart_ptr/detail/operator_bool.hpp>
674 bool unique() const BOOST_NOEXCEPT
679 long use_count() const BOOST_NOEXCEPT
681 return pn.use_count();
684 void swap( shared_ptr & other ) BOOST_NOEXCEPT
686 std::swap(px, other.px);
690 template<class Y> bool owner_before( shared_ptr<Y> const & rhs ) const BOOST_NOEXCEPT
695 template<class Y> bool owner_before( weak_ptr<Y> const & rhs ) const BOOST_NOEXCEPT
700 void * _internal_get_deleter( boost::detail::sp_typeinfo const & ti ) const BOOST_NOEXCEPT
702 return pn.get_deleter( ti );
705 void * _internal_get_untyped_deleter() const BOOST_NOEXCEPT
707 return pn.get_untyped_deleter();
710 bool _internal_equiv( shared_ptr const & r ) const BOOST_NOEXCEPT
712 return px == r.px && pn == r.pn;
715 // Tasteless as this may seem, making all members public allows member templates
716 // to work in the absence of member template friends. (Matthew Langston)
718 #ifndef BOOST_NO_MEMBER_TEMPLATE_FRIENDS
722 template<class Y> friend class shared_ptr;
723 template<class Y> friend class weak_ptr;
728 element_type * px; // contained pointer
729 boost::detail::shared_count pn; // reference counter
733 template<class T, class U> inline bool operator==(shared_ptr<T> const & a, shared_ptr<U> const & b) BOOST_NOEXCEPT
735 return a.get() == b.get();
738 template<class T, class U> inline bool operator!=(shared_ptr<T> const & a, shared_ptr<U> const & b) BOOST_NOEXCEPT
740 return a.get() != b.get();
743 #if __GNUC__ == 2 && __GNUC_MINOR__ <= 96
745 // Resolve the ambiguity between our op!= and the one in rel_ops
747 template<class T> inline bool operator!=(shared_ptr<T> const & a, shared_ptr<T> const & b) BOOST_NOEXCEPT
749 return a.get() != b.get();
754 #if !defined( BOOST_NO_CXX11_NULLPTR )
756 template<class T> inline bool operator==( shared_ptr<T> const & p, boost::detail::sp_nullptr_t ) BOOST_NOEXCEPT
761 template<class T> inline bool operator==( boost::detail::sp_nullptr_t, shared_ptr<T> const & p ) BOOST_NOEXCEPT
766 template<class T> inline bool operator!=( shared_ptr<T> const & p, boost::detail::sp_nullptr_t ) BOOST_NOEXCEPT
771 template<class T> inline bool operator!=( boost::detail::sp_nullptr_t, shared_ptr<T> const & p ) BOOST_NOEXCEPT
778 template<class T, class U> inline bool operator<(shared_ptr<T> const & a, shared_ptr<U> const & b) BOOST_NOEXCEPT
780 return a.owner_before( b );
783 template<class T> inline void swap(shared_ptr<T> & a, shared_ptr<T> & b) BOOST_NOEXCEPT
788 template<class T, class U> shared_ptr<T> static_pointer_cast( shared_ptr<U> const & r ) BOOST_NOEXCEPT
790 (void) static_cast< T* >( static_cast< U* >( 0 ) );
792 typedef typename shared_ptr<T>::element_type E;
794 E * p = static_cast< E* >( r.get() );
795 return shared_ptr<T>( r, p );
798 template<class T, class U> shared_ptr<T> const_pointer_cast( shared_ptr<U> const & r ) BOOST_NOEXCEPT
800 (void) const_cast< T* >( static_cast< U* >( 0 ) );
802 typedef typename shared_ptr<T>::element_type E;
804 E * p = const_cast< E* >( r.get() );
805 return shared_ptr<T>( r, p );
808 template<class T, class U> shared_ptr<T> dynamic_pointer_cast( shared_ptr<U> const & r ) BOOST_NOEXCEPT
810 (void) dynamic_cast< T* >( static_cast< U* >( 0 ) );
812 typedef typename shared_ptr<T>::element_type E;
814 E * p = dynamic_cast< E* >( r.get() );
815 return p? shared_ptr<T>( r, p ): shared_ptr<T>();
818 template<class T, class U> shared_ptr<T> reinterpret_pointer_cast( shared_ptr<U> const & r ) BOOST_NOEXCEPT
820 (void) reinterpret_cast< T* >( static_cast< U* >( 0 ) );
822 typedef typename shared_ptr<T>::element_type E;
824 E * p = reinterpret_cast< E* >( r.get() );
825 return shared_ptr<T>( r, p );
828 // get_pointer() enables boost::mem_fn to recognize shared_ptr
830 template<class T> inline typename shared_ptr<T>::element_type * get_pointer(shared_ptr<T> const & p) BOOST_NOEXCEPT
837 #if !defined(BOOST_NO_IOSTREAM)
839 #if defined(BOOST_NO_TEMPLATED_IOSTREAMS) || ( defined(__GNUC__) && (__GNUC__ < 3) )
841 template<class Y> std::ostream & operator<< (std::ostream & os, shared_ptr<Y> const & p)
849 // in STLport's no-iostreams mode no iostream symbols can be used
850 #ifndef _STLP_NO_IOSTREAMS
852 # if defined(BOOST_MSVC) && BOOST_WORKAROUND(BOOST_MSVC, < 1300 && __SGI_STL_PORT)
853 // MSVC6 has problems finding std::basic_ostream through the using declaration in namespace _STL
854 using std::basic_ostream;
855 template<class E, class T, class Y> basic_ostream<E, T> & operator<< (basic_ostream<E, T> & os, shared_ptr<Y> const & p)
857 template<class E, class T, class Y> std::basic_ostream<E, T> & operator<< (std::basic_ostream<E, T> & os, shared_ptr<Y> const & p)
864 #endif // _STLP_NO_IOSTREAMS
866 #endif // __GNUC__ < 3
868 #endif // !defined(BOOST_NO_IOSTREAM)
875 #if ( defined(__GNUC__) && BOOST_WORKAROUND(__GNUC__, < 3) ) || \
876 ( defined(__EDG_VERSION__) && BOOST_WORKAROUND(__EDG_VERSION__, <= 238) ) || \
877 ( defined(__HP_aCC) && BOOST_WORKAROUND(__HP_aCC, <= 33500) )
879 // g++ 2.9x doesn't allow static_cast<X const *>(void *)
880 // apparently EDG 2.38 and HP aCC A.03.35 also don't accept it
882 template<class D, class T> D * basic_get_deleter(shared_ptr<T> const & p)
884 void const * q = p._internal_get_deleter(BOOST_SP_TYPEID(D));
885 return const_cast<D *>(static_cast<D const *>(q));
890 template<class D, class T> D * basic_get_deleter( shared_ptr<T> const & p ) BOOST_NOEXCEPT
892 return static_cast<D *>( p._internal_get_deleter(BOOST_SP_TYPEID(D)) );
897 class esft2_deleter_wrapper
901 shared_ptr<void> deleter_;
905 esft2_deleter_wrapper()
909 template< class T > void set_deleter( shared_ptr<T> const & deleter )
914 template<typename D> D* get_deleter() const BOOST_NOEXCEPT
916 return boost::detail::basic_get_deleter<D>( deleter_ );
919 template< class T> void operator()( T* )
921 BOOST_ASSERT( deleter_.use_count() <= 1 );
926 } // namespace detail
928 template<class D, class T> D * get_deleter( shared_ptr<T> const & p ) BOOST_NOEXCEPT
930 D *del = boost::detail::basic_get_deleter<D>(p);
934 boost::detail::esft2_deleter_wrapper *del_wrapper = boost::detail::basic_get_deleter<boost::detail::esft2_deleter_wrapper>(p);
935 // The following get_deleter method call is fully qualified because
936 // older versions of gcc (2.95, 3.2.3) fail to compile it when written del_wrapper->get_deleter<D>()
937 if(del_wrapper) del = del_wrapper->::boost::detail::esft2_deleter_wrapper::get_deleter<D>();
945 #if !defined(BOOST_SP_NO_ATOMIC_ACCESS)
947 template<class T> inline bool atomic_is_lock_free( shared_ptr<T> const * /*p*/ ) BOOST_NOEXCEPT
952 template<class T> shared_ptr<T> atomic_load( shared_ptr<T> const * p )
954 boost::detail::spinlock_pool<2>::scoped_lock lock( p );
958 template<class T> inline shared_ptr<T> atomic_load_explicit( shared_ptr<T> const * p, memory_order /*mo*/ )
960 return atomic_load( p );
963 template<class T> void atomic_store( shared_ptr<T> * p, shared_ptr<T> r )
965 boost::detail::spinlock_pool<2>::scoped_lock lock( p );
969 template<class T> inline void atomic_store_explicit( shared_ptr<T> * p, shared_ptr<T> r, memory_order /*mo*/ )
971 atomic_store( p, r ); // std::move( r )
974 template<class T> shared_ptr<T> atomic_exchange( shared_ptr<T> * p, shared_ptr<T> r )
976 boost::detail::spinlock & sp = boost::detail::spinlock_pool<2>::spinlock_for( p );
982 return r; // return std::move( r )
985 template<class T> shared_ptr<T> atomic_exchange_explicit( shared_ptr<T> * p, shared_ptr<T> r, memory_order /*mo*/ )
987 return atomic_exchange( p, r ); // std::move( r )
990 template<class T> bool atomic_compare_exchange( shared_ptr<T> * p, shared_ptr<T> * v, shared_ptr<T> w )
992 boost::detail::spinlock & sp = boost::detail::spinlock_pool<2>::spinlock_for( p );
996 if( p->_internal_equiv( *v ) )
1006 shared_ptr<T> tmp( *p );
1015 template<class T> inline bool atomic_compare_exchange_explicit( shared_ptr<T> * p, shared_ptr<T> * v, shared_ptr<T> w, memory_order /*success*/, memory_order /*failure*/ )
1017 return atomic_compare_exchange( p, v, w ); // std::move( w )
1020 #endif // !defined(BOOST_SP_NO_ATOMIC_ACCESS)
1024 template< class T > struct hash;
1026 template< class T > std::size_t hash_value( boost::shared_ptr<T> const & p ) BOOST_NOEXCEPT
1028 return boost::hash< T* >()( p.get() );
1031 } // namespace boost
1033 #endif // #if defined(BOOST_NO_MEMBER_TEMPLATES) && !defined(BOOST_MSVC6_MEMBER_TEMPLATES)
1035 #endif // #ifndef BOOST_SMART_PTR_SHARED_PTR_HPP_INCLUDED