aboutsummaryrefslogtreecommitdiff
path: root/cutl/details/boost/smart_ptr/shared_ptr.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'cutl/details/boost/smart_ptr/shared_ptr.hpp')
-rw-r--r--cutl/details/boost/smart_ptr/shared_ptr.hpp600
1 files changed, 467 insertions, 133 deletions
diff --git a/cutl/details/boost/smart_ptr/shared_ptr.hpp b/cutl/details/boost/smart_ptr/shared_ptr.hpp
index e6556de..f528a7a 100644
--- a/cutl/details/boost/smart_ptr/shared_ptr.hpp
+++ b/cutl/details/boost/smart_ptr/shared_ptr.hpp
@@ -32,6 +32,7 @@
#include <cutl/details/boost/smart_ptr/detail/shared_count.hpp>
#include <cutl/details/boost/detail/workaround.hpp>
#include <cutl/details/boost/smart_ptr/detail/sp_convertible.hpp>
+#include <cutl/details/boost/smart_ptr/detail/sp_nullptr_t.hpp>
#if !defined(BOOST_SP_NO_ATOMIC_ACCESS)
#include <cutl/details/boost/smart_ptr/detail/spinlock_pool.hpp>
@@ -41,6 +42,7 @@
#include <algorithm> // for std::swap
#include <functional> // for std::less
#include <typeinfo> // for std::bad_cast
+#include <cstddef> // for std::size_t
#if !defined(BOOST_NO_IOSTREAM)
#if !defined(BOOST_NO_IOSFWD)
@@ -50,56 +52,157 @@
#endif
#endif
-#ifdef BOOST_MSVC // moved here to work around VC++ compiler crash
-# pragma warning(push)
-# pragma warning(disable:4284) // odd return type for operator->
-#endif
-
namespace cutl_details_boost
{
template<class T> class shared_ptr;
template<class T> class weak_ptr;
template<class T> class enable_shared_from_this;
-template<class T> class enable_shared_from_this2;
+class enable_shared_from_raw;
namespace detail
{
-struct static_cast_tag {};
-struct const_cast_tag {};
-struct dynamic_cast_tag {};
-struct polymorphic_cast_tag {};
+// sp_element, element_type
+
+template< class T > struct sp_element
+{
+ typedef T type;
+};
+
+#if !defined( BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION )
+
+template< class T > struct sp_element< T[] >
+{
+ typedef T type;
+};
+
+#if !defined( __BORLANDC__ ) || !BOOST_WORKAROUND( __BORLANDC__, < 0x600 )
+
+template< class T, std::size_t N > struct sp_element< T[N] >
+{
+ typedef T type;
+};
+
+#endif
+
+#endif // !defined( BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION )
+
+// sp_dereference, return type of operator*
-template<class T> struct shared_ptr_traits
+template< class T > struct sp_dereference
{
- typedef T & reference;
+ typedef T & type;
};
-template<> struct shared_ptr_traits<void>
+template<> struct sp_dereference< void >
{
- typedef void reference;
+ typedef void type;
};
#if !defined(BOOST_NO_CV_VOID_SPECIALIZATIONS)
-template<> struct shared_ptr_traits<void const>
+template<> struct sp_dereference< void const >
{
- typedef void reference;
+ typedef void type;
};
-template<> struct shared_ptr_traits<void volatile>
+template<> struct sp_dereference< void volatile >
{
- typedef void reference;
+ typedef void type;
};
-template<> struct shared_ptr_traits<void const volatile>
+template<> struct sp_dereference< void const volatile >
{
- typedef void reference;
+ typedef void type;
+};
+
+#endif // !defined(BOOST_NO_CV_VOID_SPECIALIZATIONS)
+
+#if !defined( BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION )
+
+template< class T > struct sp_dereference< T[] >
+{
+ typedef void type;
+};
+
+#if !defined( __BORLANDC__ ) || !BOOST_WORKAROUND( __BORLANDC__, < 0x600 )
+
+template< class T, std::size_t N > struct sp_dereference< T[N] >
+{
+ typedef void type;
};
#endif
+#endif // !defined( BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION )
+
+// sp_member_access, return type of operator->
+
+template< class T > struct sp_member_access
+{
+ typedef T * type;
+};
+
+#if !defined( BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION )
+
+template< class T > struct sp_member_access< T[] >
+{
+ typedef void type;
+};
+
+#if !defined( __BORLANDC__ ) || !BOOST_WORKAROUND( __BORLANDC__, < 0x600 )
+
+template< class T, std::size_t N > struct sp_member_access< T[N] >
+{
+ typedef void type;
+};
+
+#endif
+
+#endif // !defined( BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION )
+
+// sp_array_access, return type of operator[]
+
+template< class T > struct sp_array_access
+{
+ typedef void type;
+};
+
+#if !defined( BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION )
+
+template< class T > struct sp_array_access< T[] >
+{
+ typedef T & type;
+};
+
+#if !defined( __BORLANDC__ ) || !BOOST_WORKAROUND( __BORLANDC__, < 0x600 )
+
+template< class T, std::size_t N > struct sp_array_access< T[N] >
+{
+ typedef T & type;
+};
+
+#endif
+
+#endif // !defined( BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION )
+
+// sp_extent, for operator[] index check
+
+template< class T > struct sp_extent
+{
+ enum _vt { value = 0 };
+};
+
+#if !defined( BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION )
+
+template< class T, std::size_t N > struct sp_extent< T[N] >
+{
+ enum _vt { value = N };
+};
+
+#endif // !defined( BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION )
+
// enable_shared_from_this support
template< class X, class Y, class T > inline void sp_enable_shared_from_this( cutl_details_boost::shared_ptr<X> const * ppx, Y const * py, cutl_details_boost::enable_shared_from_this< T > const * pe )
@@ -110,13 +213,7 @@ template< class X, class Y, class T > inline void sp_enable_shared_from_this( cu
}
}
-template< class X, class Y, class T > inline void sp_enable_shared_from_this( cutl_details_boost::shared_ptr<X> * ppx, Y const * py, cutl_details_boost::enable_shared_from_this2< T > const * pe )
-{
- if( pe != 0 )
- {
- pe->_internal_accept_owner( ppx, const_cast< Y* >( py ) );
- }
-}
+template< class X, class Y > inline void sp_enable_shared_from_this( cutl_details_boost::shared_ptr<X> * ppx, Y const * py, cutl_details_boost::enable_shared_from_raw const * pe );
#ifdef _MANAGED
@@ -154,6 +251,69 @@ template< class T, class R > struct sp_enable_if_auto_ptr< std::auto_ptr< T >, R
#endif
+// sp_assert_convertible
+
+template< class Y, class T > inline void sp_assert_convertible()
+{
+#if !defined( BOOST_SP_NO_SP_CONVERTIBLE )
+
+ // static_assert( sp_convertible< Y, T >::value );
+ typedef char tmp[ sp_convertible< Y, T >::value? 1: -1 ];
+ (void)sizeof( tmp );
+
+#else
+
+ T* p = static_cast< Y* >( 0 );
+ (void)p;
+
+#endif
+}
+
+// pointer constructor helper
+
+template< class T, class Y > inline void sp_pointer_construct( cutl_details_boost::shared_ptr< T > * ppx, Y * p, cutl_details_boost::detail::shared_count & pn )
+{
+ cutl_details_boost::detail::shared_count( p ).swap( pn );
+ cutl_details_boost::detail::sp_enable_shared_from_this( ppx, p, p );
+}
+
+#if !defined( BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION )
+
+template< class T, class Y > inline void sp_pointer_construct( cutl_details_boost::shared_ptr< T[] > * /*ppx*/, Y * p, cutl_details_boost::detail::shared_count & pn )
+{
+ sp_assert_convertible< Y[], T[] >();
+ cutl_details_boost::detail::shared_count( p, cutl_details_boost::checked_array_deleter< T >() ).swap( pn );
+}
+
+template< class T, std::size_t N, class Y > inline void sp_pointer_construct( cutl_details_boost::shared_ptr< T[N] > * /*ppx*/, Y * p, cutl_details_boost::detail::shared_count & pn )
+{
+ sp_assert_convertible< Y[N], T[N] >();
+ cutl_details_boost::detail::shared_count( p, cutl_details_boost::checked_array_deleter< T >() ).swap( pn );
+}
+
+#endif // !defined( BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION )
+
+// deleter constructor helper
+
+template< class T, class Y > inline void sp_deleter_construct( cutl_details_boost::shared_ptr< T > * ppx, Y * p )
+{
+ cutl_details_boost::detail::sp_enable_shared_from_this( ppx, p, p );
+}
+
+#if !defined( BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION )
+
+template< class T, class Y > inline void sp_deleter_construct( cutl_details_boost::shared_ptr< T[] > * /*ppx*/, Y * /*p*/ )
+{
+ sp_assert_convertible< Y[], T[] >();
+}
+
+template< class T, std::size_t N, class Y > inline void sp_deleter_construct( cutl_details_boost::shared_ptr< T[N] > * /*ppx*/, Y * /*p*/ )
+{
+ sp_assert_convertible< Y[N], T[N] >();
+}
+
+#endif // !defined( BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION )
+
} // namespace detail
@@ -174,19 +334,24 @@ private:
public:
- typedef T element_type;
- typedef T value_type;
- typedef T * pointer;
- typedef typename cutl_details_boost::detail::shared_ptr_traits<T>::reference reference;
+ typedef typename cutl_details_boost::detail::sp_element< T >::type element_type;
+
+ shared_ptr() BOOST_NOEXCEPT : px( 0 ), pn() // never throws in 1.30+
+ {
+ }
+
+#if !defined( BOOST_NO_CXX11_NULLPTR )
- shared_ptr(): px(0), pn() // never throws in 1.30+
+ shared_ptr( cutl_details_boost::detail::sp_nullptr_t ) BOOST_NOEXCEPT : px( 0 ), pn() // never throws
{
}
+#endif
+
template<class Y>
- explicit shared_ptr( Y * p ): px( p ), pn( p ) // Y must be complete
+ explicit shared_ptr( Y * p ): px( p ), pn() // Y must be complete
{
- cutl_details_boost::detail::sp_enable_shared_from_this( this, p, p );
+ cutl_details_boost::detail::sp_pointer_construct( this, p, pn );
}
//
@@ -195,29 +360,58 @@ public:
// shared_ptr will release p by calling d(p)
//
- template<class Y, class D> shared_ptr(Y * p, D d): px(p), pn(p, d)
+ template<class Y, class D> shared_ptr( Y * p, D d ): px( p ), pn( p, d )
{
- cutl_details_boost::detail::sp_enable_shared_from_this( this, p, p );
+ cutl_details_boost::detail::sp_deleter_construct( this, p );
}
+#if !defined( BOOST_NO_CXX11_NULLPTR )
+
+ template<class D> shared_ptr( cutl_details_boost::detail::sp_nullptr_t p, D d ): px( p ), pn( p, d )
+ {
+ }
+
+#endif
+
// As above, but with allocator. A's copy constructor shall not throw.
template<class Y, class D, class A> shared_ptr( Y * p, D d, A a ): px( p ), pn( p, d, a )
{
- cutl_details_boost::detail::sp_enable_shared_from_this( this, p, p );
+ cutl_details_boost::detail::sp_deleter_construct( this, p );
+ }
+
+#if !defined( BOOST_NO_CXX11_NULLPTR )
+
+ template<class D, class A> shared_ptr( cutl_details_boost::detail::sp_nullptr_t p, D d, A a ): px( p ), pn( p, d, a )
+ {
+ }
+
+#endif
+
+// generated copy constructor, destructor are fine...
+
+#if !defined( BOOST_NO_CXX11_RVALUE_REFERENCES )
+
+// ... except in C++0x, move disables the implicit copy
+
+ shared_ptr( shared_ptr const & r ) BOOST_NOEXCEPT : px( r.px ), pn( r.pn )
+ {
}
-// generated copy constructor, destructor are fine
+#endif
template<class Y>
- explicit shared_ptr(weak_ptr<Y> const & r): pn(r.pn) // may throw
+ explicit shared_ptr( weak_ptr<Y> const & r ): pn( r.pn ) // may throw
{
+ cutl_details_boost::detail::sp_assert_convertible< Y, T >();
+
// it is now safe to copy r.px, as pn(r.pn) did not throw
px = r.px;
}
template<class Y>
- shared_ptr( weak_ptr<Y> const & r, cutl_details_boost::detail::sp_nothrow_tag ): px( 0 ), pn( r.pn, cutl_details_boost::detail::sp_nothrow_tag() ) // never throws
+ shared_ptr( weak_ptr<Y> const & r, cutl_details_boost::detail::sp_nothrow_tag )
+ BOOST_NOEXCEPT : px( 0 ), pn( r.pn, cutl_details_boost::detail::sp_nothrow_tag() )
{
if( !pn.empty() )
{
@@ -235,72 +429,80 @@ public:
shared_ptr( shared_ptr<Y> const & r )
#endif
- : px( r.px ), pn( r.pn ) // never throws
+ BOOST_NOEXCEPT : px( r.px ), pn( r.pn )
{
+ cutl_details_boost::detail::sp_assert_convertible< Y, T >();
}
// aliasing
template< class Y >
- shared_ptr( shared_ptr<Y> const & r, T * p ): px( p ), pn( r.pn ) // never throws
+ shared_ptr( shared_ptr<Y> const & r, element_type * p ) BOOST_NOEXCEPT : px( p ), pn( r.pn )
{
}
- template<class Y>
- shared_ptr(shared_ptr<Y> const & r, cutl_details_boost::detail::static_cast_tag): px(static_cast<element_type *>(r.px)), pn(r.pn)
- {
- }
+#ifndef BOOST_NO_AUTO_PTR
template<class Y>
- shared_ptr(shared_ptr<Y> const & r, cutl_details_boost::detail::const_cast_tag): px(const_cast<element_type *>(r.px)), pn(r.pn)
+ explicit shared_ptr( std::auto_ptr<Y> & r ): px(r.get()), pn()
{
- }
+ cutl_details_boost::detail::sp_assert_convertible< Y, T >();
- template<class Y>
- shared_ptr(shared_ptr<Y> const & r, cutl_details_boost::detail::dynamic_cast_tag): px(dynamic_cast<element_type *>(r.px)), pn(r.pn)
- {
- if(px == 0) // need to allocate new counter -- the cast failed
- {
- pn = cutl_details_boost::detail::shared_count();
- }
- }
+ Y * tmp = r.get();
+ pn = cutl_details_boost::detail::shared_count( r );
- template<class Y>
- shared_ptr(shared_ptr<Y> const & r, cutl_details_boost::detail::polymorphic_cast_tag): px(dynamic_cast<element_type *>(r.px)), pn(r.pn)
- {
- if(px == 0)
- {
- cutl_details_boost::throw_exception(std::bad_cast());
- }
+ cutl_details_boost::detail::sp_deleter_construct( this, tmp );
}
-#ifndef BOOST_NO_AUTO_PTR
+#if !defined( BOOST_NO_CXX11_RVALUE_REFERENCES )
template<class Y>
- explicit shared_ptr(std::auto_ptr<Y> & r): px(r.get()), pn()
+ shared_ptr( std::auto_ptr<Y> && r ): px(r.get()), pn()
{
+ cutl_details_boost::detail::sp_assert_convertible< Y, T >();
+
Y * tmp = r.get();
- pn = cutl_details_boost::detail::shared_count(r);
- cutl_details_boost::detail::sp_enable_shared_from_this( this, tmp, tmp );
+ pn = cutl_details_boost::detail::shared_count( r );
+
+ cutl_details_boost::detail::sp_deleter_construct( this, tmp );
}
-#if !defined( BOOST_NO_SFINAE ) && !defined( BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION )
+#elif !defined( BOOST_NO_SFINAE ) && !defined( BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION )
template<class Ap>
explicit shared_ptr( Ap r, typename cutl_details_boost::detail::sp_enable_if_auto_ptr<Ap, int>::type = 0 ): px( r.get() ), pn()
{
- typename Ap::element_type * tmp = r.get();
+ typedef typename Ap::element_type Y;
+
+ cutl_details_boost::detail::sp_assert_convertible< Y, T >();
+
+ Y * tmp = r.get();
pn = cutl_details_boost::detail::shared_count( r );
- cutl_details_boost::detail::sp_enable_shared_from_this( this, tmp, tmp );
- }
+ cutl_details_boost::detail::sp_deleter_construct( this, tmp );
+ }
#endif // BOOST_NO_SFINAE, BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
#endif // BOOST_NO_AUTO_PTR
+#if !defined( BOOST_NO_CXX11_SMART_PTR ) && !defined( BOOST_NO_CXX11_RVALUE_REFERENCES )
+
+ template< class Y, class D >
+ shared_ptr( std::unique_ptr< Y, D > && r ): px( r.get() ), pn()
+ {
+ cutl_details_boost::detail::sp_assert_convertible< Y, T >();
+
+ typename std::unique_ptr< Y, D >::pointer tmp = r.get();
+ pn = cutl_details_boost::detail::shared_count( r );
+
+ cutl_details_boost::detail::sp_deleter_construct( this, tmp );
+ }
+
+#endif
+
// assignment
- shared_ptr & operator=( shared_ptr const & r ) // never throws
+ shared_ptr & operator=( shared_ptr const & r ) BOOST_NOEXCEPT
{
this_type(r).swap(*this);
return *this;
@@ -309,7 +511,7 @@ public:
#if !defined(BOOST_MSVC) || (BOOST_MSVC >= 1400)
template<class Y>
- shared_ptr & operator=(shared_ptr<Y> const & r) // never throws
+ shared_ptr & operator=(shared_ptr<Y> const & r) BOOST_NOEXCEPT
{
this_type(r).swap(*this);
return *this;
@@ -322,11 +524,20 @@ public:
template<class Y>
shared_ptr & operator=( std::auto_ptr<Y> & r )
{
- this_type(r).swap(*this);
+ this_type( r ).swap( *this );
+ return *this;
+ }
+
+#if !defined( BOOST_NO_CXX11_RVALUE_REFERENCES )
+
+ template<class Y>
+ shared_ptr & operator=( std::auto_ptr<Y> && r )
+ {
+ this_type( static_cast< std::auto_ptr<Y> && >( r ) ).swap( *this );
return *this;
}
-#if !defined( BOOST_NO_SFINAE ) && !defined( BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION )
+#elif !defined( BOOST_NO_SFINAE ) && !defined( BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION )
template<class Ap>
typename cutl_details_boost::detail::sp_enable_if_auto_ptr< Ap, shared_ptr & >::type operator=( Ap r )
@@ -335,16 +546,26 @@ public:
return *this;
}
-
#endif // BOOST_NO_SFINAE, BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
#endif // BOOST_NO_AUTO_PTR
+#if !defined( BOOST_NO_CXX11_SMART_PTR ) && !defined( BOOST_NO_CXX11_RVALUE_REFERENCES )
+
+ template<class Y, class D>
+ shared_ptr & operator=( std::unique_ptr<Y, D> && r )
+ {
+ this_type( static_cast< std::unique_ptr<Y, D> && >( r ) ).swap(*this);
+ return *this;
+ }
+
+#endif
+
// Move support
-#if defined( BOOST_HAS_RVALUE_REFS )
+#if !defined( BOOST_NO_CXX11_RVALUE_REFERENCES )
- shared_ptr( shared_ptr && r ): px( r.px ), pn() // never throws
+ shared_ptr( shared_ptr && r ) BOOST_NOEXCEPT : px( r.px ), pn()
{
pn.swap( r.pn );
r.px = 0;
@@ -360,20 +581,22 @@ public:
shared_ptr( shared_ptr<Y> && r )
#endif
- : px( r.px ), pn() // never throws
+ BOOST_NOEXCEPT : px( r.px ), pn()
{
+ cutl_details_boost::detail::sp_assert_convertible< Y, T >();
+
pn.swap( r.pn );
r.px = 0;
}
- shared_ptr & operator=( shared_ptr && r ) // never throws
+ shared_ptr & operator=( shared_ptr && r ) BOOST_NOEXCEPT
{
this_type( static_cast< shared_ptr && >( r ) ).swap( *this );
return *this;
}
template<class Y>
- shared_ptr & operator=( shared_ptr<Y> && r ) // never throws
+ shared_ptr & operator=( shared_ptr<Y> && r ) BOOST_NOEXCEPT
{
this_type( static_cast< shared_ptr<Y> && >( r ) ).swap( *this );
return *this;
@@ -381,15 +604,25 @@ public:
#endif
- void reset() // never throws in 1.30+
+#if !defined( BOOST_NO_CXX11_NULLPTR )
+
+ shared_ptr & operator=( cutl_details_boost::detail::sp_nullptr_t ) BOOST_NOEXCEPT // never throws
+ {
+ this_type().swap(*this);
+ return *this;
+ }
+
+#endif
+
+ void reset() BOOST_NOEXCEPT // never throws in 1.30+
{
this_type().swap(*this);
}
- template<class Y> void reset(Y * p) // Y must be complete
+ template<class Y> void reset( Y * p ) // Y must be complete
{
- BOOST_ASSERT(p == 0 || p != px); // catch self-reset errors
- this_type(p).swap(*this);
+ BOOST_ASSERT( p == 0 || p != px ); // catch self-reset errors
+ this_type( p ).swap( *this );
}
template<class Y, class D> void reset( Y * p, D d )
@@ -402,24 +635,35 @@ public:
this_type( p, d, a ).swap( *this );
}
- template<class Y> void reset( shared_ptr<Y> const & r, T * p )
+ template<class Y> void reset( shared_ptr<Y> const & r, element_type * p )
{
this_type( r, p ).swap( *this );
}
-
- reference operator* () const // never throws
+
+ // never throws (but has a BOOST_ASSERT in it, so not marked with BOOST_NOEXCEPT)
+ typename cutl_details_boost::detail::sp_dereference< T >::type operator* () const
{
- BOOST_ASSERT(px != 0);
+ BOOST_ASSERT( px != 0 );
return *px;
}
-
- T * operator-> () const // never throws
+
+ // never throws (but has a BOOST_ASSERT in it, so not marked with BOOST_NOEXCEPT)
+ typename cutl_details_boost::detail::sp_member_access< T >::type operator-> () const
{
- BOOST_ASSERT(px != 0);
+ BOOST_ASSERT( px != 0 );
return px;
}
+
+ // never throws (but has a BOOST_ASSERT in it, so not marked with BOOST_NOEXCEPT)
+ typename cutl_details_boost::detail::sp_array_access< T >::type operator[] ( std::ptrdiff_t i ) const
+ {
+ BOOST_ASSERT( px != 0 );
+ BOOST_ASSERT( i >= 0 && ( i < cutl_details_boost::detail::sp_extent< T >::value || cutl_details_boost::detail::sp_extent< T >::value == 0 ) );
+
+ return px[ i ];
+ }
- T * get() const // never throws
+ element_type * get() const BOOST_NOEXCEPT
{
return px;
}
@@ -427,33 +671,43 @@ public:
// implicit conversion to "bool"
#include <cutl/details/boost/smart_ptr/detail/operator_bool.hpp>
- bool unique() const // never throws
+ bool unique() const BOOST_NOEXCEPT
{
return pn.unique();
}
- long use_count() const // never throws
+ long use_count() const BOOST_NOEXCEPT
{
return pn.use_count();
}
- void swap(shared_ptr<T> & other) // never throws
+ void swap( shared_ptr & other ) BOOST_NOEXCEPT
{
std::swap(px, other.px);
pn.swap(other.pn);
}
- template<class Y> bool _internal_less(shared_ptr<Y> const & rhs) const
+ template<class Y> bool owner_before( shared_ptr<Y> const & rhs ) const BOOST_NOEXCEPT
+ {
+ return pn < rhs.pn;
+ }
+
+ template<class Y> bool owner_before( weak_ptr<Y> const & rhs ) const BOOST_NOEXCEPT
{
return pn < rhs.pn;
}
- void * _internal_get_deleter( cutl_details_boost::detail::sp_typeinfo const & ti ) const
+ void * _internal_get_deleter( cutl_details_boost::detail::sp_typeinfo const & ti ) const BOOST_NOEXCEPT
{
return pn.get_deleter( ti );
}
- bool _internal_equiv( shared_ptr const & r ) const
+ void * _internal_get_untyped_deleter() const BOOST_NOEXCEPT
+ {
+ return pn.get_untyped_deleter();
+ }
+
+ bool _internal_equiv( shared_ptr const & r ) const BOOST_NOEXCEPT
{
return px == r.px && pn == r.pn;
}
@@ -471,17 +725,17 @@ private:
#endif
- T * px; // contained pointer
+ element_type * px; // contained pointer
cutl_details_boost::detail::shared_count pn; // reference counter
}; // shared_ptr
-template<class T, class U> inline bool operator==(shared_ptr<T> const & a, shared_ptr<U> const & b)
+template<class T, class U> inline bool operator==(shared_ptr<T> const & a, shared_ptr<U> const & b) BOOST_NOEXCEPT
{
return a.get() == b.get();
}
-template<class T, class U> inline bool operator!=(shared_ptr<T> const & a, shared_ptr<U> const & b)
+template<class T, class U> inline bool operator!=(shared_ptr<T> const & a, shared_ptr<U> const & b) BOOST_NOEXCEPT
{
return a.get() != b.get();
}
@@ -490,64 +744,90 @@ template<class T, class U> inline bool operator!=(shared_ptr<T> const & a, share
// Resolve the ambiguity between our op!= and the one in rel_ops
-template<class T> inline bool operator!=(shared_ptr<T> const & a, shared_ptr<T> const & b)
+template<class T> inline bool operator!=(shared_ptr<T> const & a, shared_ptr<T> const & b) BOOST_NOEXCEPT
{
return a.get() != b.get();
}
#endif
-template<class T, class U> inline bool operator<(shared_ptr<T> const & a, shared_ptr<U> const & b)
+#if !defined( BOOST_NO_CXX11_NULLPTR )
+
+template<class T> inline bool operator==( shared_ptr<T> const & p, cutl_details_boost::detail::sp_nullptr_t ) BOOST_NOEXCEPT
{
- return a._internal_less(b);
+ return p.get() == 0;
}
-template<class T> inline void swap(shared_ptr<T> & a, shared_ptr<T> & b)
+template<class T> inline bool operator==( cutl_details_boost::detail::sp_nullptr_t, shared_ptr<T> const & p ) BOOST_NOEXCEPT
{
- a.swap(b);
+ return p.get() == 0;
}
-template<class T, class U> shared_ptr<T> static_pointer_cast(shared_ptr<U> const & r)
+template<class T> inline bool operator!=( shared_ptr<T> const & p, cutl_details_boost::detail::sp_nullptr_t ) BOOST_NOEXCEPT
{
- return shared_ptr<T>(r, cutl_details_boost::detail::static_cast_tag());
+ return p.get() != 0;
}
-template<class T, class U> shared_ptr<T> const_pointer_cast(shared_ptr<U> const & r)
+template<class T> inline bool operator!=( cutl_details_boost::detail::sp_nullptr_t, shared_ptr<T> const & p ) BOOST_NOEXCEPT
{
- return shared_ptr<T>(r, cutl_details_boost::detail::const_cast_tag());
+ return p.get() != 0;
}
-template<class T, class U> shared_ptr<T> dynamic_pointer_cast(shared_ptr<U> const & r)
+#endif
+
+template<class T, class U> inline bool operator<(shared_ptr<T> const & a, shared_ptr<U> const & b) BOOST_NOEXCEPT
{
- return shared_ptr<T>(r, cutl_details_boost::detail::dynamic_cast_tag());
+ return a.owner_before( b );
}
-// shared_*_cast names are deprecated. Use *_pointer_cast instead.
+template<class T> inline void swap(shared_ptr<T> & a, shared_ptr<T> & b) BOOST_NOEXCEPT
+{
+ a.swap(b);
+}
-template<class T, class U> shared_ptr<T> shared_static_cast(shared_ptr<U> const & r)
+template<class T, class U> shared_ptr<T> static_pointer_cast( shared_ptr<U> const & r ) BOOST_NOEXCEPT
{
- return shared_ptr<T>(r, cutl_details_boost::detail::static_cast_tag());
+ (void) static_cast< T* >( static_cast< U* >( 0 ) );
+
+ typedef typename shared_ptr<T>::element_type E;
+
+ E * p = static_cast< E* >( r.get() );
+ return shared_ptr<T>( r, p );
}
-template<class T, class U> shared_ptr<T> shared_dynamic_cast(shared_ptr<U> const & r)
+template<class T, class U> shared_ptr<T> const_pointer_cast( shared_ptr<U> const & r ) BOOST_NOEXCEPT
{
- return shared_ptr<T>(r, cutl_details_boost::detail::dynamic_cast_tag());
+ (void) const_cast< T* >( static_cast< U* >( 0 ) );
+
+ typedef typename shared_ptr<T>::element_type E;
+
+ E * p = const_cast< E* >( r.get() );
+ return shared_ptr<T>( r, p );
}
-template<class T, class U> shared_ptr<T> shared_polymorphic_cast(shared_ptr<U> const & r)
+template<class T, class U> shared_ptr<T> dynamic_pointer_cast( shared_ptr<U> const & r ) BOOST_NOEXCEPT
{
- return shared_ptr<T>(r, cutl_details_boost::detail::polymorphic_cast_tag());
+ (void) dynamic_cast< T* >( static_cast< U* >( 0 ) );
+
+ typedef typename shared_ptr<T>::element_type E;
+
+ E * p = dynamic_cast< E* >( r.get() );
+ return p? shared_ptr<T>( r, p ): shared_ptr<T>();
}
-template<class T, class U> shared_ptr<T> shared_polymorphic_downcast(shared_ptr<U> const & r)
+template<class T, class U> shared_ptr<T> reinterpret_pointer_cast( shared_ptr<U> const & r ) BOOST_NOEXCEPT
{
- BOOST_ASSERT(dynamic_cast<T *>(r.get()) == r.get());
- return shared_static_cast<T>(r);
+ (void) reinterpret_cast< T* >( static_cast< U* >( 0 ) );
+
+ typedef typename shared_ptr<T>::element_type E;
+
+ E * p = reinterpret_cast< E* >( r.get() );
+ return shared_ptr<T>( r, p );
}
// get_pointer() enables cutl_details_boost::mem_fn to recognize shared_ptr
-template<class T> inline T * get_pointer(shared_ptr<T> const & p)
+template<class T> inline typename shared_ptr<T>::element_type * get_pointer(shared_ptr<T> const & p) BOOST_NOEXCEPT
{
return p.get();
}
@@ -589,6 +869,9 @@ template<class E, class T, class Y> std::basic_ostream<E, T> & operator<< (std::
// get_deleter
+namespace detail
+{
+
#if ( defined(__GNUC__) && BOOST_WORKAROUND(__GNUC__, < 3) ) || \
( defined(__EDG_VERSION__) && BOOST_WORKAROUND(__EDG_VERSION__, <= 238) ) || \
( defined(__HP_aCC) && BOOST_WORKAROUND(__HP_aCC, <= 33500) )
@@ -596,7 +879,7 @@ template<class E, class T, class Y> std::basic_ostream<E, T> & operator<< (std::
// g++ 2.9x doesn't allow static_cast<X const *>(void *)
// apparently EDG 2.38 and HP aCC A.03.35 also don't accept it
-template<class D, class T> D * get_deleter(shared_ptr<T> const & p)
+template<class D, class T> D * basic_get_deleter(shared_ptr<T> const & p)
{
void const * q = p._internal_get_deleter(BOOST_SP_TYPEID(D));
return const_cast<D *>(static_cast<D const *>(q));
@@ -604,18 +887,64 @@ template<class D, class T> D * get_deleter(shared_ptr<T> const & p)
#else
-template<class D, class T> D * get_deleter(shared_ptr<T> const & p)
+template<class D, class T> D * basic_get_deleter( shared_ptr<T> const & p ) BOOST_NOEXCEPT
{
- return static_cast<D *>(p._internal_get_deleter(BOOST_SP_TYPEID(D)));
+ return static_cast<D *>( p._internal_get_deleter(BOOST_SP_TYPEID(D)) );
}
#endif
+class esft2_deleter_wrapper
+{
+private:
+
+ shared_ptr<void> deleter_;
+
+public:
+
+ esft2_deleter_wrapper()
+ {
+ }
+
+ template< class T > void set_deleter( shared_ptr<T> const & deleter )
+ {
+ deleter_ = deleter;
+ }
+
+ template<typename D> D* get_deleter() const BOOST_NOEXCEPT
+ {
+ return cutl_details_boost::detail::basic_get_deleter<D>( deleter_ );
+ }
+
+ template< class T> void operator()( T* )
+ {
+ BOOST_ASSERT( deleter_.use_count() <= 1 );
+ deleter_.reset();
+ }
+};
+
+} // namespace detail
+
+template<class D, class T> D * get_deleter( shared_ptr<T> const & p ) BOOST_NOEXCEPT
+{
+ D *del = cutl_details_boost::detail::basic_get_deleter<D>(p);
+
+ if(del == 0)
+ {
+ cutl_details_boost::detail::esft2_deleter_wrapper *del_wrapper = cutl_details_boost::detail::basic_get_deleter<cutl_details_boost::detail::esft2_deleter_wrapper>(p);
+// The following get_deleter method call is fully qualified because
+// older versions of gcc (2.95, 3.2.3) fail to compile it when written del_wrapper->get_deleter<D>()
+ if(del_wrapper) del = del_wrapper->::cutl_details_boost::detail::esft2_deleter_wrapper::get_deleter<D>();
+ }
+
+ return del;
+}
+
// atomic access
#if !defined(BOOST_SP_NO_ATOMIC_ACCESS)
-template<class T> inline bool atomic_is_lock_free( shared_ptr<T> const * /*p*/ )
+template<class T> inline bool atomic_is_lock_free( shared_ptr<T> const * /*p*/ ) BOOST_NOEXCEPT
{
return false;
}
@@ -688,13 +1017,18 @@ template<class T> inline bool atomic_compare_exchange_explicit( shared_ptr<T> *
return atomic_compare_exchange( p, v, w ); // std::move( w )
}
-#endif
+#endif // !defined(BOOST_SP_NO_ATOMIC_ACCESS)
-} // namespace cutl_details_boost
+// hash_value
-#ifdef BOOST_MSVC
-# pragma warning(pop)
-#endif
+template< class T > struct hash;
+
+template< class T > std::size_t hash_value( cutl_details_boost::shared_ptr<T> const & p ) BOOST_NOEXCEPT
+{
+ return cutl_details_boost::hash< T* >()( p.get() );
+}
+
+} // namespace cutl_details_boost
#endif // #if defined(BOOST_NO_MEMBER_TEMPLATES) && !defined(BOOST_MSVC6_MEMBER_TEMPLATES)