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 // In order to avoid circular dependencies with Boost.TR1
20 // we make sure that our include of <memory> doesn't try to
21 // pull in the TR1 headers: that's why we use this header
22 // rather than including <memory> directly:
23 #include <boost/config/no_tr1/memory.hpp> // std::auto_ptr
25 #include <boost/assert.hpp>
26 #include <boost/checked_delete.hpp>
27 #include <boost/throw_exception.hpp>
28 #include <boost/smart_ptr/detail/shared_count.hpp>
29 #include <boost/detail/workaround.hpp>
30 #include <boost/smart_ptr/detail/sp_convertible.hpp>
31 #include <boost/smart_ptr/detail/sp_nullptr_t.hpp>
33 #if !defined(BOOST_SP_NO_ATOMIC_ACCESS)
34 #include <boost/smart_ptr/detail/spinlock_pool.hpp>
37 #include <algorithm> // for std::swap
38 #include <functional> // for std::less
39 #include <typeinfo> // for std::bad_cast
40 #include <cstddef> // for std::size_t
42 #if !defined(BOOST_NO_IOSTREAM)
43 #if !defined(BOOST_NO_IOSFWD)
44 #include <iosfwd> // for std::basic_ostream
53 template<class T> class shared_ptr;
54 template<class T> class weak_ptr;
55 template<class T> class enable_shared_from_this;
56 class enable_shared_from_raw;
61 template< class T, class D > class unique_ptr;
63 } // namespace movelib
68 // sp_element, element_type
70 template< class T > struct sp_element
75 #if !defined( BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION )
77 template< class T > struct sp_element< T[] >
82 #if !defined( __BORLANDC__ ) || !BOOST_WORKAROUND( __BORLANDC__, < 0x600 )
84 template< class T, std::size_t N > struct sp_element< T[N] >
91 #endif // !defined( BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION )
93 // sp_dereference, return type of operator*
95 template< class T > struct sp_dereference
100 template<> struct sp_dereference< void >
105 #if !defined(BOOST_NO_CV_VOID_SPECIALIZATIONS)
107 template<> struct sp_dereference< void const >
112 template<> struct sp_dereference< void volatile >
117 template<> struct sp_dereference< void const volatile >
122 #endif // !defined(BOOST_NO_CV_VOID_SPECIALIZATIONS)
124 #if !defined( BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION )
126 template< class T > struct sp_dereference< T[] >
131 #if !defined( __BORLANDC__ ) || !BOOST_WORKAROUND( __BORLANDC__, < 0x600 )
133 template< class T, std::size_t N > struct sp_dereference< T[N] >
140 #endif // !defined( BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION )
142 // sp_member_access, return type of operator->
144 template< class T > struct sp_member_access
149 #if !defined( BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION )
151 template< class T > struct sp_member_access< T[] >
156 #if !defined( __BORLANDC__ ) || !BOOST_WORKAROUND( __BORLANDC__, < 0x600 )
158 template< class T, std::size_t N > struct sp_member_access< T[N] >
165 #endif // !defined( BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION )
167 // sp_array_access, return type of operator[]
169 template< class T > struct sp_array_access
174 #if !defined( BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION )
176 template< class T > struct sp_array_access< T[] >
181 #if !defined( __BORLANDC__ ) || !BOOST_WORKAROUND( __BORLANDC__, < 0x600 )
183 template< class T, std::size_t N > struct sp_array_access< T[N] >
190 #endif // !defined( BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION )
192 // sp_extent, for operator[] index check
194 template< class T > struct sp_extent
196 enum _vt { value = 0 };
199 #if !defined( BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION )
201 template< class T, std::size_t N > struct sp_extent< T[N] >
203 enum _vt { value = N };
206 #endif // !defined( BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION )
208 // enable_shared_from_this support
210 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 )
214 pe->_internal_accept_owner( ppx, const_cast< Y* >( py ) );
218 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 );
222 // Avoid C4793, ... causes native code generation
224 struct sp_any_pointer
226 template<class T> sp_any_pointer( T* ) {}
229 inline void sp_enable_shared_from_this( sp_any_pointer, sp_any_pointer, sp_any_pointer )
235 inline void sp_enable_shared_from_this( ... )
241 #if !defined( BOOST_NO_SFINAE ) && !defined( BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION ) && !defined( BOOST_NO_AUTO_PTR )
243 // rvalue auto_ptr support based on a technique by Dave Abrahams
245 template< class T, class R > struct sp_enable_if_auto_ptr
249 template< class T, class R > struct sp_enable_if_auto_ptr< std::auto_ptr< T >, R >
256 // sp_assert_convertible
258 template< class Y, class T > inline void sp_assert_convertible()
260 #if !defined( BOOST_SP_NO_SP_CONVERTIBLE )
262 // static_assert( sp_convertible< Y, T >::value );
263 typedef char tmp[ sp_convertible< Y, T >::value? 1: -1 ];
268 T* p = static_cast< Y* >( 0 );
274 // pointer constructor helper
276 template< class T, class Y > inline void sp_pointer_construct( boost::shared_ptr< T > * ppx, Y * p, boost::detail::shared_count & pn )
278 boost::detail::shared_count( p ).swap( pn );
279 boost::detail::sp_enable_shared_from_this( ppx, p, p );
282 #if !defined( BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION )
284 template< class T, class Y > inline void sp_pointer_construct( boost::shared_ptr< T[] > * /*ppx*/, Y * p, boost::detail::shared_count & pn )
286 sp_assert_convertible< Y[], T[] >();
287 boost::detail::shared_count( p, boost::checked_array_deleter< T >() ).swap( pn );
290 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 )
292 sp_assert_convertible< Y[N], T[N] >();
293 boost::detail::shared_count( p, boost::checked_array_deleter< T >() ).swap( pn );
296 #endif // !defined( BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION )
298 // deleter constructor helper
300 template< class T, class Y > inline void sp_deleter_construct( boost::shared_ptr< T > * ppx, Y * p )
302 boost::detail::sp_enable_shared_from_this( ppx, p, p );
305 #if !defined( BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION )
307 template< class T, class Y > inline void sp_deleter_construct( boost::shared_ptr< T[] > * /*ppx*/, Y * /*p*/ )
309 sp_assert_convertible< Y[], T[] >();
312 template< class T, std::size_t N, class Y > inline void sp_deleter_construct( boost::shared_ptr< T[N] > * /*ppx*/, Y * /*p*/ )
314 sp_assert_convertible< Y[N], T[N] >();
317 #endif // !defined( BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION )
319 } // namespace detail
325 // An enhanced relative of scoped_ptr with reference counted copy semantics.
326 // The object pointed to is deleted when the last shared_ptr pointing to it
327 // is destroyed or reset.
330 template<class T> class shared_ptr
334 // Borland 5.5.1 specific workaround
335 typedef shared_ptr<T> this_type;
339 typedef typename boost::detail::sp_element< T >::type element_type;
341 shared_ptr() BOOST_NOEXCEPT : px( 0 ), pn() // never throws in 1.30+
345 #if !defined( BOOST_NO_CXX11_NULLPTR )
347 shared_ptr( boost::detail::sp_nullptr_t ) BOOST_NOEXCEPT : px( 0 ), pn() // never throws
354 explicit shared_ptr( Y * p ): px( p ), pn() // Y must be complete
356 boost::detail::sp_pointer_construct( this, p, pn );
360 // Requirements: D's copy constructor must not throw
362 // shared_ptr will release p by calling d(p)
365 template<class Y, class D> shared_ptr( Y * p, D d ): px( p ), pn( p, d )
367 boost::detail::sp_deleter_construct( this, p );
370 #if !defined( BOOST_NO_CXX11_NULLPTR )
372 template<class D> shared_ptr( boost::detail::sp_nullptr_t p, D d ): px( p ), pn( p, d )
378 // As above, but with allocator. A's copy constructor shall not throw.
380 template<class Y, class D, class A> shared_ptr( Y * p, D d, A a ): px( p ), pn( p, d, a )
382 boost::detail::sp_deleter_construct( this, p );
385 #if !defined( BOOST_NO_CXX11_NULLPTR )
387 template<class D, class A> shared_ptr( boost::detail::sp_nullptr_t p, D d, A a ): px( p ), pn( p, d, a )
393 // generated copy constructor, destructor are fine...
395 #if !defined( BOOST_NO_CXX11_RVALUE_REFERENCES )
397 // ... except in C++0x, move disables the implicit copy
399 shared_ptr( shared_ptr const & r ) BOOST_NOEXCEPT : px( r.px ), pn( r.pn )
406 explicit shared_ptr( weak_ptr<Y> const & r ): pn( r.pn ) // may throw
408 boost::detail::sp_assert_convertible< Y, T >();
410 // it is now safe to copy r.px, as pn(r.pn) did not throw
415 shared_ptr( weak_ptr<Y> const & r, boost::detail::sp_nothrow_tag )
416 BOOST_NOEXCEPT : px( 0 ), pn( r.pn, boost::detail::sp_nothrow_tag() )
425 #if !defined( BOOST_SP_NO_SP_CONVERTIBLE )
427 shared_ptr( shared_ptr<Y> const & r, typename boost::detail::sp_enable_if_convertible<Y,T>::type = boost::detail::sp_empty() )
431 shared_ptr( shared_ptr<Y> const & r )
434 BOOST_NOEXCEPT : px( r.px ), pn( r.pn )
436 boost::detail::sp_assert_convertible< Y, T >();
441 shared_ptr( shared_ptr<Y> const & r, element_type * p ) BOOST_NOEXCEPT : px( p ), pn( r.pn )
445 #ifndef BOOST_NO_AUTO_PTR
448 explicit shared_ptr( std::auto_ptr<Y> & r ): px(r.get()), pn()
450 boost::detail::sp_assert_convertible< Y, T >();
453 pn = boost::detail::shared_count( r );
455 boost::detail::sp_deleter_construct( this, tmp );
458 #if !defined( BOOST_NO_CXX11_RVALUE_REFERENCES )
461 shared_ptr( std::auto_ptr<Y> && r ): px(r.get()), pn()
463 boost::detail::sp_assert_convertible< Y, T >();
466 pn = boost::detail::shared_count( r );
468 boost::detail::sp_deleter_construct( this, tmp );
471 #elif !defined( BOOST_NO_SFINAE ) && !defined( BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION )
474 explicit shared_ptr( Ap r, typename boost::detail::sp_enable_if_auto_ptr<Ap, int>::type = 0 ): px( r.get() ), pn()
476 typedef typename Ap::element_type Y;
478 boost::detail::sp_assert_convertible< Y, T >();
481 pn = boost::detail::shared_count( r );
483 boost::detail::sp_deleter_construct( this, tmp );
486 #endif // BOOST_NO_SFINAE, BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
488 #endif // BOOST_NO_AUTO_PTR
490 #if !defined( BOOST_NO_CXX11_SMART_PTR ) && !defined( BOOST_NO_CXX11_RVALUE_REFERENCES )
492 template< class Y, class D >
493 shared_ptr( std::unique_ptr< Y, D > && r ): px( r.get() ), pn()
495 boost::detail::sp_assert_convertible< Y, T >();
497 typename std::unique_ptr< Y, D >::pointer tmp = r.get();
498 pn = boost::detail::shared_count( r );
500 boost::detail::sp_deleter_construct( this, tmp );
505 template< class Y, class D >
506 shared_ptr( boost::movelib::unique_ptr< Y, D > r ): px( r.get() ), pn()
508 boost::detail::sp_assert_convertible< Y, T >();
510 typename boost::movelib::unique_ptr< Y, D >::pointer tmp = r.get();
511 pn = boost::detail::shared_count( r );
513 boost::detail::sp_deleter_construct( this, tmp );
518 shared_ptr & operator=( shared_ptr const & r ) BOOST_NOEXCEPT
520 this_type(r).swap(*this);
524 #if !defined(BOOST_MSVC) || (BOOST_MSVC >= 1400)
527 shared_ptr & operator=(shared_ptr<Y> const & r) BOOST_NOEXCEPT
529 this_type(r).swap(*this);
535 #ifndef BOOST_NO_AUTO_PTR
538 shared_ptr & operator=( std::auto_ptr<Y> & r )
540 this_type( r ).swap( *this );
544 #if !defined( BOOST_NO_CXX11_RVALUE_REFERENCES )
547 shared_ptr & operator=( std::auto_ptr<Y> && r )
549 this_type( static_cast< std::auto_ptr<Y> && >( r ) ).swap( *this );
553 #elif !defined( BOOST_NO_SFINAE ) && !defined( BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION )
556 typename boost::detail::sp_enable_if_auto_ptr< Ap, shared_ptr & >::type operator=( Ap r )
558 this_type( r ).swap( *this );
562 #endif // BOOST_NO_SFINAE, BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
564 #endif // BOOST_NO_AUTO_PTR
566 #if !defined( BOOST_NO_CXX11_SMART_PTR ) && !defined( BOOST_NO_CXX11_RVALUE_REFERENCES )
568 template<class Y, class D>
569 shared_ptr & operator=( std::unique_ptr<Y, D> && r )
571 this_type( static_cast< std::unique_ptr<Y, D> && >( r ) ).swap(*this);
577 template<class Y, class D>
578 shared_ptr & operator=( boost::movelib::unique_ptr<Y, D> r )
580 // this_type( static_cast< unique_ptr<Y, D> && >( r ) ).swap( *this );
582 boost::detail::sp_assert_convertible< Y, T >();
584 typename boost::movelib::unique_ptr< Y, D >::pointer p = r.get();
589 tmp.pn = boost::detail::shared_count( r );
591 boost::detail::sp_deleter_construct( &tmp, p );
600 #if !defined( BOOST_NO_CXX11_RVALUE_REFERENCES )
602 shared_ptr( shared_ptr && r ) BOOST_NOEXCEPT : px( r.px ), pn()
609 #if !defined( BOOST_SP_NO_SP_CONVERTIBLE )
611 shared_ptr( shared_ptr<Y> && r, typename boost::detail::sp_enable_if_convertible<Y,T>::type = boost::detail::sp_empty() )
615 shared_ptr( shared_ptr<Y> && r )
618 BOOST_NOEXCEPT : px( r.px ), pn()
620 boost::detail::sp_assert_convertible< Y, T >();
626 shared_ptr & operator=( shared_ptr && r ) BOOST_NOEXCEPT
628 this_type( static_cast< shared_ptr && >( r ) ).swap( *this );
633 shared_ptr & operator=( shared_ptr<Y> && r ) BOOST_NOEXCEPT
635 this_type( static_cast< shared_ptr<Y> && >( r ) ).swap( *this );
641 #if !defined( BOOST_NO_CXX11_NULLPTR )
643 shared_ptr & operator=( boost::detail::sp_nullptr_t ) BOOST_NOEXCEPT // never throws
645 this_type().swap(*this);
651 void reset() BOOST_NOEXCEPT // never throws in 1.30+
653 this_type().swap(*this);
656 template<class Y> void reset( Y * p ) // Y must be complete
658 BOOST_ASSERT( p == 0 || p != px ); // catch self-reset errors
659 this_type( p ).swap( *this );
662 template<class Y, class D> void reset( Y * p, D d )
664 this_type( p, d ).swap( *this );
667 template<class Y, class D, class A> void reset( Y * p, D d, A a )
669 this_type( p, d, a ).swap( *this );
672 template<class Y> void reset( shared_ptr<Y> const & r, element_type * p )
674 this_type( r, p ).swap( *this );
677 // never throws (but has a BOOST_ASSERT in it, so not marked with BOOST_NOEXCEPT)
678 typename boost::detail::sp_dereference< T >::type operator* () const
680 BOOST_ASSERT( px != 0 );
684 // never throws (but has a BOOST_ASSERT in it, so not marked with BOOST_NOEXCEPT)
685 typename boost::detail::sp_member_access< T >::type operator-> () const
687 BOOST_ASSERT( px != 0 );
691 // never throws (but has a BOOST_ASSERT in it, so not marked with BOOST_NOEXCEPT)
692 typename boost::detail::sp_array_access< T >::type operator[] ( std::ptrdiff_t i ) const
694 BOOST_ASSERT( px != 0 );
695 BOOST_ASSERT( i >= 0 && ( i < boost::detail::sp_extent< T >::value || boost::detail::sp_extent< T >::value == 0 ) );
697 return static_cast< typename boost::detail::sp_array_access< T >::type >( px[ i ] );
700 element_type * get() const BOOST_NOEXCEPT
705 // implicit conversion to "bool"
706 #include <boost/smart_ptr/detail/operator_bool.hpp>
708 bool unique() const BOOST_NOEXCEPT
713 long use_count() const BOOST_NOEXCEPT
715 return pn.use_count();
718 void swap( shared_ptr & other ) BOOST_NOEXCEPT
720 std::swap(px, other.px);
724 template<class Y> bool owner_before( shared_ptr<Y> const & rhs ) const BOOST_NOEXCEPT
729 template<class Y> bool owner_before( weak_ptr<Y> const & rhs ) const BOOST_NOEXCEPT
734 void * _internal_get_deleter( boost::detail::sp_typeinfo const & ti ) const BOOST_NOEXCEPT
736 return pn.get_deleter( ti );
739 void * _internal_get_untyped_deleter() const BOOST_NOEXCEPT
741 return pn.get_untyped_deleter();
744 bool _internal_equiv( shared_ptr const & r ) const BOOST_NOEXCEPT
746 return px == r.px && pn == r.pn;
749 // Tasteless as this may seem, making all members public allows member templates
750 // to work in the absence of member template friends. (Matthew Langston)
752 #ifndef BOOST_NO_MEMBER_TEMPLATE_FRIENDS
756 template<class Y> friend class shared_ptr;
757 template<class Y> friend class weak_ptr;
762 element_type * px; // contained pointer
763 boost::detail::shared_count pn; // reference counter
767 template<class T, class U> inline bool operator==(shared_ptr<T> const & a, shared_ptr<U> const & b) BOOST_NOEXCEPT
769 return a.get() == b.get();
772 template<class T, class U> inline bool operator!=(shared_ptr<T> const & a, shared_ptr<U> const & b) BOOST_NOEXCEPT
774 return a.get() != b.get();
777 #if __GNUC__ == 2 && __GNUC_MINOR__ <= 96
779 // Resolve the ambiguity between our op!= and the one in rel_ops
781 template<class T> inline bool operator!=(shared_ptr<T> const & a, shared_ptr<T> const & b) BOOST_NOEXCEPT
783 return a.get() != b.get();
788 #if !defined( BOOST_NO_CXX11_NULLPTR )
790 template<class T> inline bool operator==( shared_ptr<T> const & p, boost::detail::sp_nullptr_t ) BOOST_NOEXCEPT
795 template<class T> inline bool operator==( boost::detail::sp_nullptr_t, shared_ptr<T> const & p ) BOOST_NOEXCEPT
800 template<class T> inline bool operator!=( shared_ptr<T> const & p, boost::detail::sp_nullptr_t ) BOOST_NOEXCEPT
805 template<class T> inline bool operator!=( boost::detail::sp_nullptr_t, shared_ptr<T> const & p ) BOOST_NOEXCEPT
812 template<class T, class U> inline bool operator<(shared_ptr<T> const & a, shared_ptr<U> const & b) BOOST_NOEXCEPT
814 return a.owner_before( b );
817 template<class T> inline void swap(shared_ptr<T> & a, shared_ptr<T> & b) BOOST_NOEXCEPT
822 template<class T, class U> shared_ptr<T> static_pointer_cast( shared_ptr<U> const & r ) BOOST_NOEXCEPT
824 (void) static_cast< T* >( static_cast< U* >( 0 ) );
826 typedef typename shared_ptr<T>::element_type E;
828 E * p = static_cast< E* >( r.get() );
829 return shared_ptr<T>( r, p );
832 template<class T, class U> shared_ptr<T> const_pointer_cast( shared_ptr<U> const & r ) BOOST_NOEXCEPT
834 (void) const_cast< T* >( static_cast< U* >( 0 ) );
836 typedef typename shared_ptr<T>::element_type E;
838 E * p = const_cast< E* >( r.get() );
839 return shared_ptr<T>( r, p );
842 template<class T, class U> shared_ptr<T> dynamic_pointer_cast( shared_ptr<U> const & r ) BOOST_NOEXCEPT
844 (void) dynamic_cast< T* >( static_cast< U* >( 0 ) );
846 typedef typename shared_ptr<T>::element_type E;
848 E * p = dynamic_cast< E* >( r.get() );
849 return p? shared_ptr<T>( r, p ): shared_ptr<T>();
852 template<class T, class U> shared_ptr<T> reinterpret_pointer_cast( shared_ptr<U> const & r ) BOOST_NOEXCEPT
854 (void) reinterpret_cast< T* >( static_cast< U* >( 0 ) );
856 typedef typename shared_ptr<T>::element_type E;
858 E * p = reinterpret_cast< E* >( r.get() );
859 return shared_ptr<T>( r, p );
862 // get_pointer() enables boost::mem_fn to recognize shared_ptr
864 template<class T> inline typename shared_ptr<T>::element_type * get_pointer(shared_ptr<T> const & p) BOOST_NOEXCEPT
871 #if !defined(BOOST_NO_IOSTREAM)
873 #if defined(BOOST_NO_TEMPLATED_IOSTREAMS) || ( defined(__GNUC__) && (__GNUC__ < 3) )
875 template<class Y> std::ostream & operator<< (std::ostream & os, shared_ptr<Y> const & p)
883 // in STLport's no-iostreams mode no iostream symbols can be used
884 #ifndef _STLP_NO_IOSTREAMS
886 # if defined(BOOST_MSVC) && BOOST_WORKAROUND(BOOST_MSVC, < 1300 && __SGI_STL_PORT)
887 // MSVC6 has problems finding std::basic_ostream through the using declaration in namespace _STL
888 using std::basic_ostream;
889 template<class E, class T, class Y> basic_ostream<E, T> & operator<< (basic_ostream<E, T> & os, shared_ptr<Y> const & p)
891 template<class E, class T, class Y> std::basic_ostream<E, T> & operator<< (std::basic_ostream<E, T> & os, shared_ptr<Y> const & p)
898 #endif // _STLP_NO_IOSTREAMS
900 #endif // __GNUC__ < 3
902 #endif // !defined(BOOST_NO_IOSTREAM)
909 #if ( defined(__GNUC__) && BOOST_WORKAROUND(__GNUC__, < 3) ) || \
910 ( defined(__EDG_VERSION__) && BOOST_WORKAROUND(__EDG_VERSION__, <= 238) ) || \
911 ( defined(__HP_aCC) && BOOST_WORKAROUND(__HP_aCC, <= 33500) )
913 // g++ 2.9x doesn't allow static_cast<X const *>(void *)
914 // apparently EDG 2.38 and HP aCC A.03.35 also don't accept it
916 template<class D, class T> D * basic_get_deleter(shared_ptr<T> const & p)
918 void const * q = p._internal_get_deleter(BOOST_SP_TYPEID(D));
919 return const_cast<D *>(static_cast<D const *>(q));
924 template<class D, class T> D * basic_get_deleter( shared_ptr<T> const & p ) BOOST_NOEXCEPT
926 return static_cast<D *>( p._internal_get_deleter(BOOST_SP_TYPEID(D)) );
931 class esft2_deleter_wrapper
935 shared_ptr<void const volatile> deleter_;
939 esft2_deleter_wrapper()
943 template< class T > void set_deleter( shared_ptr<T> const & deleter )
948 template<typename D> D* get_deleter() const BOOST_NOEXCEPT
950 return boost::detail::basic_get_deleter<D>( deleter_ );
953 template< class T> void operator()( T* )
955 BOOST_ASSERT( deleter_.use_count() <= 1 );
960 } // namespace detail
962 template<class D, class T> D * get_deleter( shared_ptr<T> const & p ) BOOST_NOEXCEPT
964 D *del = boost::detail::basic_get_deleter<D>(p);
968 boost::detail::esft2_deleter_wrapper *del_wrapper = boost::detail::basic_get_deleter<boost::detail::esft2_deleter_wrapper>(p);
969 // The following get_deleter method call is fully qualified because
970 // older versions of gcc (2.95, 3.2.3) fail to compile it when written del_wrapper->get_deleter<D>()
971 if(del_wrapper) del = del_wrapper->::boost::detail::esft2_deleter_wrapper::get_deleter<D>();
979 #if !defined(BOOST_SP_NO_ATOMIC_ACCESS)
981 template<class T> inline bool atomic_is_lock_free( shared_ptr<T> const * /*p*/ ) BOOST_NOEXCEPT
986 template<class T> shared_ptr<T> atomic_load( shared_ptr<T> const * p )
988 boost::detail::spinlock_pool<2>::scoped_lock lock( p );
992 template<class T> inline shared_ptr<T> atomic_load_explicit( shared_ptr<T> const * p, /*memory_order mo*/ int )
994 return atomic_load( p );
997 template<class T> void atomic_store( shared_ptr<T> * p, shared_ptr<T> r )
999 boost::detail::spinlock_pool<2>::scoped_lock lock( p );
1003 template<class T> inline void atomic_store_explicit( shared_ptr<T> * p, shared_ptr<T> r, /*memory_order mo*/ int )
1005 atomic_store( p, r ); // std::move( r )
1008 template<class T> shared_ptr<T> atomic_exchange( shared_ptr<T> * p, shared_ptr<T> r )
1010 boost::detail::spinlock & sp = boost::detail::spinlock_pool<2>::spinlock_for( p );
1016 return r; // return std::move( r )
1019 template<class T> shared_ptr<T> atomic_exchange_explicit( shared_ptr<T> * p, shared_ptr<T> r, /*memory_order mo*/ int )
1021 return atomic_exchange( p, r ); // std::move( r )
1024 template<class T> bool atomic_compare_exchange( shared_ptr<T> * p, shared_ptr<T> * v, shared_ptr<T> w )
1026 boost::detail::spinlock & sp = boost::detail::spinlock_pool<2>::spinlock_for( p );
1030 if( p->_internal_equiv( *v ) )
1040 shared_ptr<T> tmp( *p );
1049 template<class T> inline bool atomic_compare_exchange_explicit( shared_ptr<T> * p, shared_ptr<T> * v, shared_ptr<T> w, /*memory_order success*/ int, /*memory_order failure*/ int )
1051 return atomic_compare_exchange( p, v, w ); // std::move( w )
1054 #endif // !defined(BOOST_SP_NO_ATOMIC_ACCESS)
1058 template< class T > struct hash;
1060 template< class T > std::size_t hash_value( boost::shared_ptr<T> const & p ) BOOST_NOEXCEPT
1062 return boost::hash< T* >()( p.get() );
1065 } // namespace boost
1067 #endif // #ifndef BOOST_SMART_PTR_SHARED_PTR_HPP_INCLUDED