forked from boostorg/smart_ptr
Optimize make_local_shared to use a single allocation
This commit is contained in:
@ -55,9 +55,9 @@ public:
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void destroy() BOOST_SP_NOEXCEPT = 0;
|
virtual void local_cb_destroy() BOOST_SP_NOEXCEPT = 0;
|
||||||
|
|
||||||
virtual boost::shared_ptr<void> get_shared_ptr() const BOOST_SP_NOEXCEPT = 0;
|
virtual boost::shared_ptr<void> local_cb_get_shared_ptr() const BOOST_SP_NOEXCEPT = 0;
|
||||||
|
|
||||||
void add_ref() BOOST_SP_NOEXCEPT
|
void add_ref() BOOST_SP_NOEXCEPT
|
||||||
{
|
{
|
||||||
@ -78,7 +78,7 @@ public:
|
|||||||
|
|
||||||
if( local_use_count_ == 0 )
|
if( local_use_count_ == 0 )
|
||||||
{
|
{
|
||||||
destroy();
|
local_cb_destroy();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -112,12 +112,12 @@ public:
|
|||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
virtual void destroy() BOOST_SP_NOEXCEPT
|
virtual void local_cb_destroy() BOOST_SP_NOEXCEPT
|
||||||
{
|
{
|
||||||
delete this;
|
delete this;
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual boost::shared_ptr<void> get_shared_ptr() const BOOST_SP_NOEXCEPT
|
virtual boost::shared_ptr<void> local_cb_get_shared_ptr() const BOOST_SP_NOEXCEPT
|
||||||
{
|
{
|
||||||
return const_pointer_cast<void>( pn_ );
|
return const_pointer_cast<void>( pn_ );
|
||||||
}
|
}
|
||||||
@ -129,12 +129,12 @@ public:
|
|||||||
|
|
||||||
boost::shared_ptr<void const volatile> pn_;
|
boost::shared_ptr<void const volatile> pn_;
|
||||||
|
|
||||||
virtual void destroy() BOOST_SP_NOEXCEPT
|
virtual void local_cb_destroy() BOOST_SP_NOEXCEPT
|
||||||
{
|
{
|
||||||
pn_.reset();
|
pn_.reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual boost::shared_ptr<void> get_shared_ptr() const BOOST_SP_NOEXCEPT
|
virtual boost::shared_ptr<void> local_cb_get_shared_ptr() const BOOST_SP_NOEXCEPT
|
||||||
{
|
{
|
||||||
return const_pointer_cast<void>( pn_ );
|
return const_pointer_cast<void>( pn_ );
|
||||||
}
|
}
|
||||||
|
@ -132,6 +132,10 @@ template< class E, class P, class D, class A > inline void lsp_allocator_constru
|
|||||||
pn = pd;
|
pn = pd;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct lsp_internal_constructor_tag
|
||||||
|
{
|
||||||
|
};
|
||||||
|
|
||||||
} // namespace detail
|
} // namespace detail
|
||||||
|
|
||||||
//
|
//
|
||||||
@ -184,6 +188,11 @@ public:
|
|||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
// internal constructor, used by make_shared
|
||||||
|
BOOST_CONSTEXPR local_shared_ptr( boost::detail::lsp_internal_constructor_tag, T * px_, boost::detail::local_counted_base * pn_ ) BOOST_SP_NOEXCEPT : px( px_ ), pn( pn_ )
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
template<class Y>
|
template<class Y>
|
||||||
explicit local_shared_ptr( Y * p ): px( p ), pn( 0 )
|
explicit local_shared_ptr( Y * p ): px( p ), pn( 0 )
|
||||||
{
|
{
|
||||||
@ -484,7 +493,7 @@ public:
|
|||||||
|
|
||||||
if( pn )
|
if( pn )
|
||||||
{
|
{
|
||||||
return static_pointer_cast<Y>( pn->get_shared_ptr() );
|
return static_pointer_cast<Y>( pn->local_cb_get_shared_ptr() );
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -502,7 +511,7 @@ public:
|
|||||||
|
|
||||||
if( pn )
|
if( pn )
|
||||||
{
|
{
|
||||||
return static_pointer_cast<Y>( pn->get_shared_ptr() );
|
return static_pointer_cast<Y>( pn->local_cb_get_shared_ptr() );
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -12,6 +12,7 @@
|
|||||||
// See http://www.boost.org/libs/smart_ptr/ for documentation.
|
// See http://www.boost.org/libs/smart_ptr/ for documentation.
|
||||||
|
|
||||||
#include <boost/smart_ptr/local_shared_ptr.hpp>
|
#include <boost/smart_ptr/local_shared_ptr.hpp>
|
||||||
|
#include <boost/smart_ptr/detail/local_counted_base.hpp>
|
||||||
#include <boost/smart_ptr/make_shared.hpp>
|
#include <boost/smart_ptr/make_shared.hpp>
|
||||||
#include <boost/config.hpp>
|
#include <boost/config.hpp>
|
||||||
#include <utility>
|
#include <utility>
|
||||||
@ -23,6 +24,8 @@ namespace boost
|
|||||||
namespace detail
|
namespace detail
|
||||||
{
|
{
|
||||||
|
|
||||||
|
// lsp_if_not_array
|
||||||
|
|
||||||
template<class T> struct lsp_if_not_array
|
template<class T> struct lsp_if_not_array
|
||||||
{
|
{
|
||||||
typedef boost::local_shared_ptr<T> type;
|
typedef boost::local_shared_ptr<T> type;
|
||||||
@ -36,26 +39,142 @@ template<class T, std::size_t N> struct lsp_if_not_array<T[N]>
|
|||||||
{
|
{
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// lsp_ms_deleter
|
||||||
|
|
||||||
|
template<class T, class A> class lsp_ms_deleter: public local_counted_impl_em
|
||||||
|
{
|
||||||
|
private:
|
||||||
|
|
||||||
|
typedef typename sp_aligned_storage<sizeof(T), ::boost::alignment_of<T>::value>::type storage_type;
|
||||||
|
|
||||||
|
storage_type storage_;
|
||||||
|
A a_;
|
||||||
|
bool initialized_;
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
void destroy() BOOST_SP_NOEXCEPT
|
||||||
|
{
|
||||||
|
if( initialized_ )
|
||||||
|
{
|
||||||
|
T * p = reinterpret_cast< T* >( storage_.data_ );
|
||||||
|
|
||||||
|
#if !defined( BOOST_NO_CXX11_ALLOCATOR )
|
||||||
|
|
||||||
|
std::allocator_traits<A>::destroy( a_, p );
|
||||||
|
|
||||||
|
#else
|
||||||
|
|
||||||
|
p->~T();
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
initialized_ = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
explicit lsp_ms_deleter( A const & a ) BOOST_SP_NOEXCEPT : a_( a ), initialized_( false )
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
// optimization: do not copy storage_
|
||||||
|
lsp_ms_deleter( lsp_ms_deleter const & r ) BOOST_SP_NOEXCEPT : a_( r.a_), initialized_( false )
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
~lsp_ms_deleter() BOOST_SP_NOEXCEPT
|
||||||
|
{
|
||||||
|
destroy();
|
||||||
|
}
|
||||||
|
|
||||||
|
void operator()( T * ) BOOST_SP_NOEXCEPT
|
||||||
|
{
|
||||||
|
destroy();
|
||||||
|
}
|
||||||
|
|
||||||
|
static void operator_fn( T* ) BOOST_SP_NOEXCEPT // operator() can't be static
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void * address() BOOST_SP_NOEXCEPT
|
||||||
|
{
|
||||||
|
return storage_.data_;
|
||||||
|
}
|
||||||
|
|
||||||
|
void set_initialized() BOOST_SP_NOEXCEPT
|
||||||
|
{
|
||||||
|
initialized_ = true;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
} // namespace detail
|
} // namespace detail
|
||||||
|
|
||||||
template<class T, class... Args> typename boost::detail::lsp_if_not_array<T>::type make_local_shared( Args&&... args )
|
|
||||||
{
|
|
||||||
return boost::make_shared<T>( std::forward<Args>(args)... );
|
|
||||||
}
|
|
||||||
|
|
||||||
template<class T> typename boost::detail::lsp_if_not_array<T>::type make_local_shared_noinit()
|
|
||||||
{
|
|
||||||
return boost::make_shared_noinit<T>();
|
|
||||||
}
|
|
||||||
|
|
||||||
template<class T, class A, class... Args> typename boost::detail::lsp_if_not_array<T>::type allocate_local_shared( A const & a, Args&&... args )
|
template<class T, class A, class... Args> typename boost::detail::lsp_if_not_array<T>::type allocate_local_shared( A const & a, Args&&... args )
|
||||||
{
|
{
|
||||||
return boost::allocate_shared<T>( a, std::forward<Args>(args)... );
|
typedef typename std::allocator_traits<A>::template rebind_alloc<T> A2;
|
||||||
|
A2 a2( a );
|
||||||
|
|
||||||
|
typedef boost::detail::lsp_ms_deleter<T, A2> D;
|
||||||
|
|
||||||
|
boost::shared_ptr<T> pt( static_cast< T* >( 0 ), boost::detail::sp_inplace_tag<D>(), a2 );
|
||||||
|
|
||||||
|
D * pd = static_cast< D* >( pt._internal_get_untyped_deleter() );
|
||||||
|
void * pv = pd->address();
|
||||||
|
|
||||||
|
#if !defined( BOOST_NO_CXX11_ALLOCATOR )
|
||||||
|
|
||||||
|
std::allocator_traits<A2>::construct( a2, static_cast< T* >( pv ), std::forward<Args>( args )... );
|
||||||
|
|
||||||
|
#else
|
||||||
|
|
||||||
|
::new( pv ) T( std::forward<Args>( args )... );
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
pd->set_initialized();
|
||||||
|
|
||||||
|
T * pt2 = static_cast< T* >( pv );
|
||||||
|
boost::detail::sp_enable_shared_from_this( &pt, pt2, pt2 );
|
||||||
|
|
||||||
|
pd->pn_ = boost::shared_ptr<T>( pt, pt2 );
|
||||||
|
|
||||||
|
return boost::local_shared_ptr<T>( boost::detail::lsp_internal_constructor_tag(), pt2, pd );
|
||||||
}
|
}
|
||||||
|
|
||||||
template<class T, class A> typename boost::detail::lsp_if_not_array<T>::type allocate_local_shared_noinit( A const & a )
|
template<class T, class A> typename boost::detail::lsp_if_not_array<T>::type allocate_local_shared_noinit( A const & a )
|
||||||
{
|
{
|
||||||
return boost::allocate_shared_noinit<T>( a );
|
typedef typename std::allocator_traits<A>::template rebind_alloc<T> A2;
|
||||||
|
A2 a2( a );
|
||||||
|
|
||||||
|
typedef boost::detail::lsp_ms_deleter<T, A2> D;
|
||||||
|
|
||||||
|
boost::shared_ptr<T> pt( static_cast< T* >( 0 ), boost::detail::sp_inplace_tag<D>(), a2 );
|
||||||
|
|
||||||
|
D * pd = static_cast< D* >( pt._internal_get_untyped_deleter() );
|
||||||
|
void * pv = pd->address();
|
||||||
|
|
||||||
|
::new( pv ) T;
|
||||||
|
|
||||||
|
pd->set_initialized();
|
||||||
|
|
||||||
|
T * pt2 = static_cast< T* >( pv );
|
||||||
|
boost::detail::sp_enable_shared_from_this( &pt, pt2, pt2 );
|
||||||
|
|
||||||
|
pd->pn_ = boost::shared_ptr<T>( pt, pt2 );
|
||||||
|
|
||||||
|
return boost::local_shared_ptr<T>( boost::detail::lsp_internal_constructor_tag(), pt2, pd );
|
||||||
|
}
|
||||||
|
|
||||||
|
template<class T, class... Args> typename boost::detail::lsp_if_not_array<T>::type make_local_shared( Args&&... args )
|
||||||
|
{
|
||||||
|
return boost::allocate_local_shared<T>( std::allocator<T>(), std::forward<Args>(args)... );
|
||||||
|
}
|
||||||
|
|
||||||
|
template<class T> typename boost::detail::lsp_if_not_array<T>::type make_local_shared_noinit()
|
||||||
|
{
|
||||||
|
return boost::allocate_shared_noinit<T>( std::allocator<T>() );
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace boost
|
} // namespace boost
|
||||||
|
@ -48,21 +48,21 @@ int X::instances = 0;
|
|||||||
|
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
BOOST_TEST( X::instances == 0 );
|
BOOST_TEST_EQ( X::instances, 0 );
|
||||||
|
|
||||||
{
|
{
|
||||||
boost::shared_ptr< X > px = boost::allocate_local_shared< X >( std::allocator<void>() );
|
boost::shared_ptr< X > px = boost::allocate_local_shared< X >( std::allocator<void>() );
|
||||||
BOOST_TEST( X::instances == 1 );
|
BOOST_TEST_EQ( X::instances, 1 );
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
boost::shared_ptr< X > qx = px->shared_from_this();
|
boost::shared_ptr< X > qx = px->shared_from_this();
|
||||||
|
|
||||||
BOOST_TEST( px == qx );
|
BOOST_TEST_EQ( px, qx );
|
||||||
BOOST_TEST( !( px < qx ) && !( qx < px ) );
|
BOOST_TEST( !( px < qx ) && !( qx < px ) );
|
||||||
|
|
||||||
px.reset();
|
px.reset();
|
||||||
BOOST_TEST( X::instances == 1 );
|
BOOST_TEST_EQ( X::instances, 1 );
|
||||||
}
|
}
|
||||||
catch( boost::bad_weak_ptr const& )
|
catch( boost::bad_weak_ptr const& )
|
||||||
{
|
{
|
||||||
@ -70,21 +70,43 @@ int main()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_TEST( X::instances == 0 );
|
BOOST_TEST_EQ( X::instances, 0 );
|
||||||
|
|
||||||
|
{
|
||||||
|
boost::shared_ptr< X > px = boost::allocate_local_shared_noinit< X >( std::allocator<void>() );
|
||||||
|
BOOST_TEST_EQ( X::instances, 1 );
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
boost::shared_ptr< X > qx = px->shared_from_this();
|
||||||
|
|
||||||
|
BOOST_TEST_EQ( px, qx );
|
||||||
|
BOOST_TEST( !( px < qx ) && !( qx < px ) );
|
||||||
|
|
||||||
|
px.reset();
|
||||||
|
BOOST_TEST_EQ( X::instances, 1 );
|
||||||
|
}
|
||||||
|
catch( boost::bad_weak_ptr const& )
|
||||||
|
{
|
||||||
|
BOOST_ERROR( "px->shared_from_this() failed" );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
BOOST_TEST_EQ( X::instances, 0 );
|
||||||
|
|
||||||
{
|
{
|
||||||
boost::shared_ptr< X > px = boost::allocate_local_shared< X >( std::allocator<void>(), 1 );
|
boost::shared_ptr< X > px = boost::allocate_local_shared< X >( std::allocator<void>(), 1 );
|
||||||
BOOST_TEST( X::instances == 1 );
|
BOOST_TEST_EQ( X::instances, 1 );
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
boost::shared_ptr< X > qx = px->shared_from_this();
|
boost::shared_ptr< X > qx = px->shared_from_this();
|
||||||
|
|
||||||
BOOST_TEST( px == qx );
|
BOOST_TEST_EQ( px, qx );
|
||||||
BOOST_TEST( !( px < qx ) && !( qx < px ) );
|
BOOST_TEST( !( px < qx ) && !( qx < px ) );
|
||||||
|
|
||||||
px.reset();
|
px.reset();
|
||||||
BOOST_TEST( X::instances == 1 );
|
BOOST_TEST_EQ( X::instances, 1 );
|
||||||
}
|
}
|
||||||
catch( boost::bad_weak_ptr const& )
|
catch( boost::bad_weak_ptr const& )
|
||||||
{
|
{
|
||||||
@ -92,21 +114,21 @@ int main()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_TEST( X::instances == 0 );
|
BOOST_TEST_EQ( X::instances, 0 );
|
||||||
|
|
||||||
{
|
{
|
||||||
boost::shared_ptr< X > px = boost::allocate_local_shared< X >( std::allocator<void>(), 1, 2 );
|
boost::shared_ptr< X > px = boost::allocate_local_shared< X >( std::allocator<void>(), 1, 2 );
|
||||||
BOOST_TEST( X::instances == 1 );
|
BOOST_TEST_EQ( X::instances, 1 );
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
boost::shared_ptr< X > qx = px->shared_from_this();
|
boost::shared_ptr< X > qx = px->shared_from_this();
|
||||||
|
|
||||||
BOOST_TEST( px == qx );
|
BOOST_TEST_EQ( px, qx );
|
||||||
BOOST_TEST( !( px < qx ) && !( qx < px ) );
|
BOOST_TEST( !( px < qx ) && !( qx < px ) );
|
||||||
|
|
||||||
px.reset();
|
px.reset();
|
||||||
BOOST_TEST( X::instances == 1 );
|
BOOST_TEST_EQ( X::instances, 1 );
|
||||||
}
|
}
|
||||||
catch( boost::bad_weak_ptr const& )
|
catch( boost::bad_weak_ptr const& )
|
||||||
{
|
{
|
||||||
@ -114,21 +136,21 @@ int main()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_TEST( X::instances == 0 );
|
BOOST_TEST_EQ( X::instances, 0 );
|
||||||
|
|
||||||
{
|
{
|
||||||
boost::shared_ptr< X > px = boost::allocate_local_shared< X >( std::allocator<void>(), 1, 2, 3 );
|
boost::shared_ptr< X > px = boost::allocate_local_shared< X >( std::allocator<void>(), 1, 2, 3 );
|
||||||
BOOST_TEST( X::instances == 1 );
|
BOOST_TEST_EQ( X::instances, 1 );
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
boost::shared_ptr< X > qx = px->shared_from_this();
|
boost::shared_ptr< X > qx = px->shared_from_this();
|
||||||
|
|
||||||
BOOST_TEST( px == qx );
|
BOOST_TEST_EQ( px, qx );
|
||||||
BOOST_TEST( !( px < qx ) && !( qx < px ) );
|
BOOST_TEST( !( px < qx ) && !( qx < px ) );
|
||||||
|
|
||||||
px.reset();
|
px.reset();
|
||||||
BOOST_TEST( X::instances == 1 );
|
BOOST_TEST_EQ( X::instances, 1 );
|
||||||
}
|
}
|
||||||
catch( boost::bad_weak_ptr const& )
|
catch( boost::bad_weak_ptr const& )
|
||||||
{
|
{
|
||||||
@ -136,21 +158,21 @@ int main()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_TEST( X::instances == 0 );
|
BOOST_TEST_EQ( X::instances, 0 );
|
||||||
|
|
||||||
{
|
{
|
||||||
boost::shared_ptr< X > px = boost::allocate_local_shared< X >( std::allocator<void>(), 1, 2, 3, 4 );
|
boost::shared_ptr< X > px = boost::allocate_local_shared< X >( std::allocator<void>(), 1, 2, 3, 4 );
|
||||||
BOOST_TEST( X::instances == 1 );
|
BOOST_TEST_EQ( X::instances, 1 );
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
boost::shared_ptr< X > qx = px->shared_from_this();
|
boost::shared_ptr< X > qx = px->shared_from_this();
|
||||||
|
|
||||||
BOOST_TEST( px == qx );
|
BOOST_TEST_EQ( px, qx );
|
||||||
BOOST_TEST( !( px < qx ) && !( qx < px ) );
|
BOOST_TEST( !( px < qx ) && !( qx < px ) );
|
||||||
|
|
||||||
px.reset();
|
px.reset();
|
||||||
BOOST_TEST( X::instances == 1 );
|
BOOST_TEST_EQ( X::instances, 1 );
|
||||||
}
|
}
|
||||||
catch( boost::bad_weak_ptr const& )
|
catch( boost::bad_weak_ptr const& )
|
||||||
{
|
{
|
||||||
@ -158,21 +180,21 @@ int main()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_TEST( X::instances == 0 );
|
BOOST_TEST_EQ( X::instances, 0 );
|
||||||
|
|
||||||
{
|
{
|
||||||
boost::shared_ptr< X > px = boost::allocate_local_shared< X >( std::allocator<void>(), 1, 2, 3, 4, 5 );
|
boost::shared_ptr< X > px = boost::allocate_local_shared< X >( std::allocator<void>(), 1, 2, 3, 4, 5 );
|
||||||
BOOST_TEST( X::instances == 1 );
|
BOOST_TEST_EQ( X::instances, 1 );
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
boost::shared_ptr< X > qx = px->shared_from_this();
|
boost::shared_ptr< X > qx = px->shared_from_this();
|
||||||
|
|
||||||
BOOST_TEST( px == qx );
|
BOOST_TEST_EQ( px, qx );
|
||||||
BOOST_TEST( !( px < qx ) && !( qx < px ) );
|
BOOST_TEST( !( px < qx ) && !( qx < px ) );
|
||||||
|
|
||||||
px.reset();
|
px.reset();
|
||||||
BOOST_TEST( X::instances == 1 );
|
BOOST_TEST_EQ( X::instances, 1 );
|
||||||
}
|
}
|
||||||
catch( boost::bad_weak_ptr const& )
|
catch( boost::bad_weak_ptr const& )
|
||||||
{
|
{
|
||||||
@ -180,21 +202,21 @@ int main()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_TEST( X::instances == 0 );
|
BOOST_TEST_EQ( X::instances, 0 );
|
||||||
|
|
||||||
{
|
{
|
||||||
boost::shared_ptr< X > px = boost::allocate_local_shared< X >( std::allocator<void>(), 1, 2, 3, 4, 5, 6 );
|
boost::shared_ptr< X > px = boost::allocate_local_shared< X >( std::allocator<void>(), 1, 2, 3, 4, 5, 6 );
|
||||||
BOOST_TEST( X::instances == 1 );
|
BOOST_TEST_EQ( X::instances, 1 );
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
boost::shared_ptr< X > qx = px->shared_from_this();
|
boost::shared_ptr< X > qx = px->shared_from_this();
|
||||||
|
|
||||||
BOOST_TEST( px == qx );
|
BOOST_TEST_EQ( px, qx );
|
||||||
BOOST_TEST( !( px < qx ) && !( qx < px ) );
|
BOOST_TEST( !( px < qx ) && !( qx < px ) );
|
||||||
|
|
||||||
px.reset();
|
px.reset();
|
||||||
BOOST_TEST( X::instances == 1 );
|
BOOST_TEST_EQ( X::instances, 1 );
|
||||||
}
|
}
|
||||||
catch( boost::bad_weak_ptr const& )
|
catch( boost::bad_weak_ptr const& )
|
||||||
{
|
{
|
||||||
@ -202,21 +224,21 @@ int main()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_TEST( X::instances == 0 );
|
BOOST_TEST_EQ( X::instances, 0 );
|
||||||
|
|
||||||
{
|
{
|
||||||
boost::shared_ptr< X > px = boost::allocate_local_shared< X >( std::allocator<void>(), 1, 2, 3, 4, 5, 6, 7 );
|
boost::shared_ptr< X > px = boost::allocate_local_shared< X >( std::allocator<void>(), 1, 2, 3, 4, 5, 6, 7 );
|
||||||
BOOST_TEST( X::instances == 1 );
|
BOOST_TEST_EQ( X::instances, 1 );
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
boost::shared_ptr< X > qx = px->shared_from_this();
|
boost::shared_ptr< X > qx = px->shared_from_this();
|
||||||
|
|
||||||
BOOST_TEST( px == qx );
|
BOOST_TEST_EQ( px, qx );
|
||||||
BOOST_TEST( !( px < qx ) && !( qx < px ) );
|
BOOST_TEST( !( px < qx ) && !( qx < px ) );
|
||||||
|
|
||||||
px.reset();
|
px.reset();
|
||||||
BOOST_TEST( X::instances == 1 );
|
BOOST_TEST_EQ( X::instances, 1 );
|
||||||
}
|
}
|
||||||
catch( boost::bad_weak_ptr const& )
|
catch( boost::bad_weak_ptr const& )
|
||||||
{
|
{
|
||||||
@ -224,21 +246,21 @@ int main()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_TEST( X::instances == 0 );
|
BOOST_TEST_EQ( X::instances, 0 );
|
||||||
|
|
||||||
{
|
{
|
||||||
boost::shared_ptr< X > px = boost::allocate_local_shared< X >( std::allocator<void>(), 1, 2, 3, 4, 5, 6, 7, 8 );
|
boost::shared_ptr< X > px = boost::allocate_local_shared< X >( std::allocator<void>(), 1, 2, 3, 4, 5, 6, 7, 8 );
|
||||||
BOOST_TEST( X::instances == 1 );
|
BOOST_TEST_EQ( X::instances, 1 );
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
boost::shared_ptr< X > qx = px->shared_from_this();
|
boost::shared_ptr< X > qx = px->shared_from_this();
|
||||||
|
|
||||||
BOOST_TEST( px == qx );
|
BOOST_TEST_EQ( px, qx );
|
||||||
BOOST_TEST( !( px < qx ) && !( qx < px ) );
|
BOOST_TEST( !( px < qx ) && !( qx < px ) );
|
||||||
|
|
||||||
px.reset();
|
px.reset();
|
||||||
BOOST_TEST( X::instances == 1 );
|
BOOST_TEST_EQ( X::instances, 1 );
|
||||||
}
|
}
|
||||||
catch( boost::bad_weak_ptr const& )
|
catch( boost::bad_weak_ptr const& )
|
||||||
{
|
{
|
||||||
@ -246,21 +268,21 @@ int main()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_TEST( X::instances == 0 );
|
BOOST_TEST_EQ( X::instances, 0 );
|
||||||
|
|
||||||
{
|
{
|
||||||
boost::shared_ptr< X > px = boost::allocate_local_shared< X >( std::allocator<void>(), 1, 2, 3, 4, 5, 6, 7, 8, 9 );
|
boost::shared_ptr< X > px = boost::allocate_local_shared< X >( std::allocator<void>(), 1, 2, 3, 4, 5, 6, 7, 8, 9 );
|
||||||
BOOST_TEST( X::instances == 1 );
|
BOOST_TEST_EQ( X::instances, 1 );
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
boost::shared_ptr< X > qx = px->shared_from_this();
|
boost::shared_ptr< X > qx = px->shared_from_this();
|
||||||
|
|
||||||
BOOST_TEST( px == qx );
|
BOOST_TEST_EQ( px, qx );
|
||||||
BOOST_TEST( !( px < qx ) && !( qx < px ) );
|
BOOST_TEST( !( px < qx ) && !( qx < px ) );
|
||||||
|
|
||||||
px.reset();
|
px.reset();
|
||||||
BOOST_TEST( X::instances == 1 );
|
BOOST_TEST_EQ( X::instances, 1 );
|
||||||
}
|
}
|
||||||
catch( boost::bad_weak_ptr const& )
|
catch( boost::bad_weak_ptr const& )
|
||||||
{
|
{
|
||||||
@ -268,7 +290,7 @@ int main()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_TEST( X::instances == 0 );
|
BOOST_TEST_EQ( X::instances, 0 );
|
||||||
|
|
||||||
return boost::report_errors();
|
return boost::report_errors();
|
||||||
}
|
}
|
||||||
|
@ -62,6 +62,28 @@ int main()
|
|||||||
|
|
||||||
BOOST_TEST( X::instances == 0 );
|
BOOST_TEST( X::instances == 0 );
|
||||||
|
|
||||||
|
{
|
||||||
|
boost::shared_ptr< X > px = boost::allocate_shared_noinit< X >( std::allocator<void>() );
|
||||||
|
BOOST_TEST( X::instances == 1 );
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
boost::shared_ptr< X > qx = px->shared_from_this();
|
||||||
|
|
||||||
|
BOOST_TEST( px == qx );
|
||||||
|
BOOST_TEST( !( px < qx ) && !( qx < px ) );
|
||||||
|
|
||||||
|
px.reset();
|
||||||
|
BOOST_TEST( X::instances == 1 );
|
||||||
|
}
|
||||||
|
catch( boost::bad_weak_ptr const& )
|
||||||
|
{
|
||||||
|
BOOST_ERROR( "px->shared_from_this() failed" );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
BOOST_TEST( X::instances == 0 );
|
||||||
|
|
||||||
{
|
{
|
||||||
boost::shared_ptr< X > px = boost::allocate_shared< X >( std::allocator<void>(), 1 );
|
boost::shared_ptr< X > px = boost::allocate_shared< X >( std::allocator<void>(), 1 );
|
||||||
BOOST_TEST( X::instances == 1 );
|
BOOST_TEST( X::instances == 1 );
|
||||||
|
@ -61,6 +61,12 @@ int main()
|
|||||||
BOOST_TEST( *pi == 0 );
|
BOOST_TEST( *pi == 0 );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
boost::shared_ptr< int > pi = boost::allocate_shared_noinit< int >( std::allocator<int>() );
|
||||||
|
|
||||||
|
BOOST_TEST( pi.get() != 0 );
|
||||||
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
boost::shared_ptr< int > pi = boost::allocate_shared< int >( std::allocator<int>(), 5 );
|
boost::shared_ptr< int > pi = boost::allocate_shared< int >( std::allocator<int>(), 5 );
|
||||||
|
|
||||||
@ -83,6 +89,19 @@ int main()
|
|||||||
BOOST_TEST( X::instances == 0 );
|
BOOST_TEST( X::instances == 0 );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
boost::shared_ptr< X > pi = boost::allocate_shared_noinit< X >( std::allocator<void>() );
|
||||||
|
boost::weak_ptr<X> wp( pi );
|
||||||
|
|
||||||
|
BOOST_TEST( X::instances == 1 );
|
||||||
|
BOOST_TEST( pi.get() != 0 );
|
||||||
|
BOOST_TEST( pi->v == 0 );
|
||||||
|
|
||||||
|
pi.reset();
|
||||||
|
|
||||||
|
BOOST_TEST( X::instances == 0 );
|
||||||
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
boost::shared_ptr< X > pi = boost::allocate_shared< X >( std::allocator<void>(), 1 );
|
boost::shared_ptr< X > pi = boost::allocate_shared< X >( std::allocator<void>(), 1 );
|
||||||
boost::weak_ptr<X> wp( pi );
|
boost::weak_ptr<X> wp( pi );
|
||||||
|
@ -71,6 +71,28 @@ int main()
|
|||||||
|
|
||||||
BOOST_TEST( X::instances == 0 );
|
BOOST_TEST( X::instances == 0 );
|
||||||
|
|
||||||
|
{
|
||||||
|
boost::shared_ptr< X > px = boost::make_local_shared_noinit< X >();
|
||||||
|
BOOST_TEST( X::instances == 1 );
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
boost::shared_ptr< X > qx = px->shared_from_this();
|
||||||
|
|
||||||
|
BOOST_TEST( px == qx );
|
||||||
|
BOOST_TEST( !( px < qx ) && !( qx < px ) );
|
||||||
|
|
||||||
|
px.reset();
|
||||||
|
BOOST_TEST( X::instances == 1 );
|
||||||
|
}
|
||||||
|
catch( boost::bad_weak_ptr const& )
|
||||||
|
{
|
||||||
|
BOOST_ERROR( "px->shared_from_this() failed" );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
BOOST_TEST( X::instances == 0 );
|
||||||
|
|
||||||
{
|
{
|
||||||
boost::shared_ptr< X > px = boost::make_local_shared< X >( 1 );
|
boost::shared_ptr< X > px = boost::make_local_shared< X >( 1 );
|
||||||
BOOST_TEST( X::instances == 1 );
|
BOOST_TEST( X::instances == 1 );
|
||||||
|
@ -61,6 +61,28 @@ int main()
|
|||||||
|
|
||||||
BOOST_TEST( X::instances == 0 );
|
BOOST_TEST( X::instances == 0 );
|
||||||
|
|
||||||
|
{
|
||||||
|
boost::shared_ptr< X > px = boost::make_shared_noinit< X >();
|
||||||
|
BOOST_TEST( X::instances == 1 );
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
boost::shared_ptr< X > qx = px->shared_from_this();
|
||||||
|
|
||||||
|
BOOST_TEST( px == qx );
|
||||||
|
BOOST_TEST( !( px < qx ) && !( qx < px ) );
|
||||||
|
|
||||||
|
px.reset();
|
||||||
|
BOOST_TEST( X::instances == 1 );
|
||||||
|
}
|
||||||
|
catch( boost::bad_weak_ptr const& )
|
||||||
|
{
|
||||||
|
BOOST_ERROR( "px->shared_from_this() failed" );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
BOOST_TEST( X::instances == 0 );
|
||||||
|
|
||||||
{
|
{
|
||||||
boost::shared_ptr< X > px = boost::make_shared< X >( 1 );
|
boost::shared_ptr< X > px = boost::make_shared< X >( 1 );
|
||||||
BOOST_TEST( X::instances == 1 );
|
BOOST_TEST( X::instances == 1 );
|
||||||
|
@ -61,6 +61,12 @@ int main()
|
|||||||
BOOST_TEST( *pi == 0 );
|
BOOST_TEST( *pi == 0 );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
boost::shared_ptr< int > pi = boost::make_shared_noinit< int >();
|
||||||
|
|
||||||
|
BOOST_TEST( pi.get() != 0 );
|
||||||
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
boost::shared_ptr< int > pi = boost::make_shared< int >( 5 );
|
boost::shared_ptr< int > pi = boost::make_shared< int >( 5 );
|
||||||
|
|
||||||
@ -83,6 +89,19 @@ int main()
|
|||||||
BOOST_TEST( X::instances == 0 );
|
BOOST_TEST( X::instances == 0 );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
boost::shared_ptr< X > pi = boost::make_shared_noinit< X >();
|
||||||
|
boost::weak_ptr<X> wp( pi );
|
||||||
|
|
||||||
|
BOOST_TEST( X::instances == 1 );
|
||||||
|
BOOST_TEST( pi.get() != 0 );
|
||||||
|
BOOST_TEST( pi->v == 0 );
|
||||||
|
|
||||||
|
pi.reset();
|
||||||
|
|
||||||
|
BOOST_TEST( X::instances == 0 );
|
||||||
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
boost::shared_ptr< X > pi = boost::make_shared< X >( 1 );
|
boost::shared_ptr< X > pi = boost::make_shared< X >( 1 );
|
||||||
boost::weak_ptr<X> wp( pi );
|
boost::weak_ptr<X> wp( pi );
|
||||||
|
Reference in New Issue
Block a user