|
Boost-Commit : |
From: pdimov_at_[hidden]
Date: 2008-05-01 12:50:40
Author: pdimov
Date: 2008-05-01 12:50:39 EDT (Thu, 01 May 2008)
New Revision: 44979
URL: http://svn.boost.org/trac/boost/changeset/44979
Log:
make_shared added; tweaks for old compilers; fixes #1884.
Added:
trunk/boost/make_shared.hpp (contents, props changed)
trunk/libs/smart_ptr/test/make_shared_test.cpp (contents, props changed)
Text files modified:
trunk/boost/detail/shared_count.hpp | 9 ++++++++-
trunk/boost/detail/spinlock_w32.hpp | 2 +-
trunk/boost/detail/yield_k.hpp | 2 +-
trunk/boost/type_traits/type_with_alignment.hpp | 2 +-
trunk/libs/smart_ptr/test/Jamfile.v2 | 1 +
5 files changed, 12 insertions(+), 4 deletions(-)
Modified: trunk/boost/detail/shared_count.hpp
==============================================================================
--- trunk/boost/detail/shared_count.hpp (original)
+++ trunk/boost/detail/shared_count.hpp 2008-05-01 12:50:39 EDT (Thu, 01 May 2008)
@@ -104,11 +104,18 @@
#endif
}
- template<class P, class D> shared_count(P p, D d): pi_(0)
+#if defined( BOOST_MSVC ) && BOOST_WORKAROUND( BOOST_MSVC, <= 1200 )
+ template<class Y, class D> shared_count( Y * p, D d ): pi_(0)
+#else
+ template<class P, class D> shared_count( P p, D d ): pi_(0)
+#endif
#if defined(BOOST_SP_ENABLE_DEBUG_HOOKS)
, id_(shared_count_id)
#endif
{
+#if defined( BOOST_MSVC ) && BOOST_WORKAROUND( BOOST_MSVC, <= 1200 )
+ typedef Y* P;
+#endif
#ifndef BOOST_NO_EXCEPTIONS
try
Modified: trunk/boost/detail/spinlock_w32.hpp
==============================================================================
--- trunk/boost/detail/spinlock_w32.hpp (original)
+++ trunk/boost/detail/spinlock_w32.hpp 2008-05-01 12:50:39 EDT (Thu, 01 May 2008)
@@ -33,7 +33,7 @@
#elif defined(__GNUC__)
-#define BOOST_COMPILER_FENCE __asm__ __volatile__( "" ::: "memory" );
+#define BOOST_COMPILER_FENCE __asm__ __volatile__( "" : : : "memory" );
#else
Modified: trunk/boost/detail/yield_k.hpp
==============================================================================
--- trunk/boost/detail/yield_k.hpp (original)
+++ trunk/boost/detail/yield_k.hpp 2008-05-01 12:50:39 EDT (Thu, 01 May 2008)
@@ -36,7 +36,7 @@
#elif defined(__GNUC__) && ( defined(__i386__) || defined(__x86_64__) )
-#define BOOST_SMT_PAUSE __asm__ __volatile__( "rep; nop" ::: "memory" );
+#define BOOST_SMT_PAUSE __asm__ __volatile__( "rep; nop" : : : "memory" );
#endif
Added: trunk/boost/make_shared.hpp
==============================================================================
--- (empty file)
+++ trunk/boost/make_shared.hpp 2008-05-01 12:50:39 EDT (Thu, 01 May 2008)
@@ -0,0 +1,433 @@
+#ifndef BOOST_MAKE_SHARED_HPP_INCLUDED
+#define BOOST_MAKE_SHARED_HPP_INCLUDED
+
+// make_shared.hpp
+//
+// Copyright (c) 2007, 2008 Peter Dimov
+//
+// Distributed under the Boost Software License, Version 1.0.
+// See accompanying file LICENSE_1_0.txt or copy at
+// http://www.boost.org/LICENSE_1_0.txt
+//
+// See http://www.boost.org/libs/smart_ptr/make_shared.html
+// for documentation.
+
+#include <boost/config.hpp>
+#include <boost/shared_ptr.hpp>
+#include <boost/type_traits/type_with_alignment.hpp>
+#include <boost/type_traits/alignment_of.hpp>
+#include <cstddef>
+#include <new>
+
+namespace boost
+{
+
+namespace detail
+{
+
+template< std::size_t N, std::size_t A > struct sp_aligned_storage
+{
+ union type
+ {
+ char data_[ N ];
+ typename boost::type_with_alignment< A >::type align_;
+ };
+};
+
+template< class T > class sp_ms_deleter
+{
+private:
+
+ typedef typename sp_aligned_storage< sizeof( T ), ::boost::alignment_of< T >::value >::type storage_type;
+
+ bool initialized_;
+ storage_type storage_;
+
+private:
+
+ void destroy()
+ {
+ if( initialized_ )
+ {
+ reinterpret_cast< T* >( storage_.data_ )->~T();
+ initialized_ = false;
+ }
+ }
+
+public:
+
+ sp_ms_deleter(): initialized_( false )
+ {
+ }
+
+ ~sp_ms_deleter()
+ {
+ destroy();
+ }
+
+ void operator()( T * )
+ {
+ destroy();
+ }
+
+ void * address()
+ {
+ return storage_.data_;
+ }
+
+ void set_initialized()
+ {
+ initialized_ = true;
+ }
+};
+
+template< class T > T forward( T t )
+{
+ return t;
+}
+
+} // namespace detail
+
+// Zero-argument versions
+//
+// Used even when variadic templates are available because of the new T() vs new T issue
+
+template< class T > boost::shared_ptr< T > make_shared()
+{
+ boost::shared_ptr< T > pt( static_cast< T* >( 0 ), detail::sp_ms_deleter< T >() );
+
+ detail::sp_ms_deleter< T > * pd = boost::get_deleter< detail::sp_ms_deleter< T > >( pt );
+
+ void * pv = pd->address();
+
+ new( pv ) T();
+ pd->set_initialized();
+
+ return boost::shared_ptr< T >( pt, static_cast< T* >( pv ) );
+}
+
+template< class T, class A > boost::shared_ptr< T > allocate_shared( A const & a )
+{
+ boost::shared_ptr< T > pt( static_cast< T* >( 0 ), detail::sp_ms_deleter< T >(), a );
+
+ detail::sp_ms_deleter< T > * pd = boost::get_deleter< detail::sp_ms_deleter< T > >( pt );
+
+ void * pv = pd->address();
+
+ new( pv ) T();
+ pd->set_initialized();
+
+ return boost::shared_ptr< T >( pt, static_cast< T* >( pv ) );
+}
+
+#if defined( BOOST_HAS_VARIADIC_TMPL ) && defined( BOOST_HAS_RVALUE_REFS )
+
+// Variadic templates, rvalue reference
+
+template< class T, class... Args > boost::shared_ptr< T > make_shared( Args && ... args )
+{
+ boost::shared_ptr< T > pt( static_cast< T* >( 0 ), detail::sp_ms_deleter< T >() );
+
+ detail::sp_ms_deleter< T > * pd = boost::get_deleter< detail::sp_ms_deleter< T > >( pt );
+
+ void * pv = pd->address();
+
+ new( pv ) T( detail::forward<Args>( args )... );
+ pd->set_initialized();
+
+ return boost::shared_ptr< T >( pt, static_cast< T* >( pv ) );
+}
+
+template< class T, class A, class... Args > boost::shared_ptr< T > allocate_shared( A const & a, Args && ... args )
+{
+ boost::shared_ptr< T > pt( static_cast< T* >( 0 ), detail::sp_ms_deleter< T >(), a );
+
+ detail::sp_ms_deleter< T > * pd = boost::get_deleter< detail::sp_ms_deleter< T > >( pt );
+
+ void * pv = pd->address();
+
+ new( pv ) T( detail::forward<Args>( args )... );
+ pd->set_initialized();
+
+ return boost::shared_ptr< T >( pt, static_cast< T* >( pv ) );
+}
+
+#else
+
+// C++03 version
+
+template< class T, class A1 >
+boost::shared_ptr< T > make_shared( A1 const & a1 )
+{
+ boost::shared_ptr< T > pt( static_cast< T* >( 0 ), detail::sp_ms_deleter< T >() );
+
+ detail::sp_ms_deleter< T > * pd = boost::get_deleter< detail::sp_ms_deleter< T > >( pt );
+
+ void * pv = pd->address();
+
+ new( pv ) T( a1 );
+ pd->set_initialized();
+
+ return boost::shared_ptr< T >( pt, static_cast< T* >( pv ) );
+}
+
+template< class T, class A, class A1 >
+boost::shared_ptr< T > allocate_shared( A const & a, A1 const & a1 )
+{
+ boost::shared_ptr< T > pt( static_cast< T* >( 0 ), detail::sp_ms_deleter< T >(), a );
+
+ detail::sp_ms_deleter< T > * pd = boost::get_deleter< detail::sp_ms_deleter< T > >( pt );
+
+ void * pv = pd->address();
+
+ new( pv ) T( a1 );
+ pd->set_initialized();
+
+ return boost::shared_ptr< T >( pt, static_cast< T* >( pv ) );
+}
+
+template< class T, class A1, class A2 >
+boost::shared_ptr< T > make_shared( A1 const & a1, A2 const & a2 )
+{
+ boost::shared_ptr< T > pt( static_cast< T* >( 0 ), detail::sp_ms_deleter< T >() );
+
+ detail::sp_ms_deleter< T > * pd = boost::get_deleter< detail::sp_ms_deleter< T > >( pt );
+
+ void * pv = pd->address();
+
+ new( pv ) T( a1, a2 );
+ pd->set_initialized();
+
+ return boost::shared_ptr< T >( pt, static_cast< T* >( pv ) );
+}
+
+template< class T, class A, class A1, class A2 >
+boost::shared_ptr< T > allocate_shared( A const & a, A1 const & a1, A2 const & a2 )
+{
+ boost::shared_ptr< T > pt( static_cast< T* >( 0 ), detail::sp_ms_deleter< T >(), a );
+
+ detail::sp_ms_deleter< T > * pd = boost::get_deleter< detail::sp_ms_deleter< T > >( pt );
+
+ void * pv = pd->address();
+
+ new( pv ) T( a1, a2 );
+ pd->set_initialized();
+
+ return boost::shared_ptr< T >( pt, static_cast< T* >( pv ) );
+}
+
+template< class T, class A1, class A2, class A3 >
+boost::shared_ptr< T > make_shared( A1 const & a1, A2 const & a2, A3 const & a3 )
+{
+ boost::shared_ptr< T > pt( static_cast< T* >( 0 ), detail::sp_ms_deleter< T >() );
+
+ detail::sp_ms_deleter< T > * pd = boost::get_deleter< detail::sp_ms_deleter< T > >( pt );
+
+ void * pv = pd->address();
+
+ new( pv ) T( a1, a2, a3 );
+ pd->set_initialized();
+
+ return boost::shared_ptr< T >( pt, static_cast< T* >( pv ) );
+}
+
+template< class T, class A, class A1, class A2, class A3 >
+boost::shared_ptr< T > allocate_shared( A const & a, A1 const & a1, A2 const & a2, A3 const & a3 )
+{
+ boost::shared_ptr< T > pt( static_cast< T* >( 0 ), detail::sp_ms_deleter< T >(), a );
+
+ detail::sp_ms_deleter< T > * pd = boost::get_deleter< detail::sp_ms_deleter< T > >( pt );
+
+ void * pv = pd->address();
+
+ new( pv ) T( a1, a2, a3 );
+ pd->set_initialized();
+
+ return boost::shared_ptr< T >( pt, static_cast< T* >( pv ) );
+}
+
+template< class T, class A1, class A2, class A3, class A4 >
+boost::shared_ptr< T > make_shared( A1 const & a1, A2 const & a2, A3 const & a3, A4 const & a4 )
+{
+ boost::shared_ptr< T > pt( static_cast< T* >( 0 ), detail::sp_ms_deleter< T >() );
+
+ detail::sp_ms_deleter< T > * pd = boost::get_deleter< detail::sp_ms_deleter< T > >( pt );
+
+ void * pv = pd->address();
+
+ new( pv ) T( a1, a2, a3, a4 );
+ pd->set_initialized();
+
+ return boost::shared_ptr< T >( pt, static_cast< T* >( pv ) );
+}
+
+template< class T, class A, class A1, class A2, class A3, class A4 >
+boost::shared_ptr< T > allocate_shared( A const & a, A1 const & a1, A2 const & a2, A3 const & a3, A4 const & a4 )
+{
+ boost::shared_ptr< T > pt( static_cast< T* >( 0 ), detail::sp_ms_deleter< T >(), a );
+
+ detail::sp_ms_deleter< T > * pd = boost::get_deleter< detail::sp_ms_deleter< T > >( pt );
+
+ void * pv = pd->address();
+
+ new( pv ) T( a1, a2, a3, a4 );
+ pd->set_initialized();
+
+ return boost::shared_ptr< T >( pt, static_cast< T* >( pv ) );
+}
+
+template< class T, class A1, class A2, class A3, class A4, class A5 >
+boost::shared_ptr< T > make_shared( A1 const & a1, A2 const & a2, A3 const & a3, A4 const & a4, A5 const & a5 )
+{
+ boost::shared_ptr< T > pt( static_cast< T* >( 0 ), detail::sp_ms_deleter< T >() );
+
+ detail::sp_ms_deleter< T > * pd = boost::get_deleter< detail::sp_ms_deleter< T > >( pt );
+
+ void * pv = pd->address();
+
+ new( pv ) T( a1, a2, a3, a4, a5 );
+ pd->set_initialized();
+
+ return boost::shared_ptr< T >( pt, static_cast< T* >( pv ) );
+}
+
+template< class T, class A, class A1, class A2, class A3, class A4, class A5 >
+boost::shared_ptr< T > allocate_shared( A const & a, A1 const & a1, A2 const & a2, A3 const & a3, A4 const & a4, A5 const & a5 )
+{
+ boost::shared_ptr< T > pt( static_cast< T* >( 0 ), detail::sp_ms_deleter< T >(), a );
+
+ detail::sp_ms_deleter< T > * pd = boost::get_deleter< detail::sp_ms_deleter< T > >( pt );
+
+ void * pv = pd->address();
+
+ new( pv ) T( a1, a2, a3, a4, a5 );
+ pd->set_initialized();
+
+ return boost::shared_ptr< T >( pt, static_cast< T* >( pv ) );
+}
+
+template< class T, class A1, class A2, class A3, class A4, class A5, class A6 >
+boost::shared_ptr< T > make_shared( A1 const & a1, A2 const & a2, A3 const & a3, A4 const & a4, A5 const & a5, A6 const & a6 )
+{
+ boost::shared_ptr< T > pt( static_cast< T* >( 0 ), detail::sp_ms_deleter< T >() );
+
+ detail::sp_ms_deleter< T > * pd = boost::get_deleter< detail::sp_ms_deleter< T > >( pt );
+
+ void * pv = pd->address();
+
+ new( pv ) T( a1, a2, a3, a4, a5, a6 );
+ pd->set_initialized();
+
+ return boost::shared_ptr< T >( pt, static_cast< T* >( pv ) );
+}
+
+template< class T, class A, class A1, class A2, class A3, class A4, class A5, class A6 >
+boost::shared_ptr< T > allocate_shared( A const & a, A1 const & a1, A2 const & a2, A3 const & a3, A4 const & a4, A5 const & a5, A6 const & a6 )
+{
+ boost::shared_ptr< T > pt( static_cast< T* >( 0 ), detail::sp_ms_deleter< T >(), a );
+
+ detail::sp_ms_deleter< T > * pd = boost::get_deleter< detail::sp_ms_deleter< T > >( pt );
+
+ void * pv = pd->address();
+
+ new( pv ) T( a1, a2, a3, a4, a5, a6 );
+ pd->set_initialized();
+
+ return boost::shared_ptr< T >( pt, static_cast< T* >( pv ) );
+}
+
+template< class T, class A1, class A2, class A3, class A4, class A5, class A6, class A7 >
+boost::shared_ptr< T > make_shared( A1 const & a1, A2 const & a2, A3 const & a3, A4 const & a4, A5 const & a5, A6 const & a6, A7 const & a7 )
+{
+ boost::shared_ptr< T > pt( static_cast< T* >( 0 ), detail::sp_ms_deleter< T >() );
+
+ detail::sp_ms_deleter< T > * pd = boost::get_deleter< detail::sp_ms_deleter< T > >( pt );
+
+ void * pv = pd->address();
+
+ new( pv ) T( a1, a2, a3, a4, a5, a6, a7 );
+ pd->set_initialized();
+
+ return boost::shared_ptr< T >( pt, static_cast< T* >( pv ) );
+}
+
+template< class T, class A, class A1, class A2, class A3, class A4, class A5, class A6, class A7 >
+boost::shared_ptr< T > allocate_shared( A const & a, A1 const & a1, A2 const & a2, A3 const & a3, A4 const & a4, A5 const & a5, A6 const & a6, A7 const & a7 )
+{
+ boost::shared_ptr< T > pt( static_cast< T* >( 0 ), detail::sp_ms_deleter< T >(), a );
+
+ detail::sp_ms_deleter< T > * pd = boost::get_deleter< detail::sp_ms_deleter< T > >( pt );
+
+ void * pv = pd->address();
+
+ new( pv ) T( a1, a2, a3, a4, a5, a6, a7 );
+ pd->set_initialized();
+
+ return boost::shared_ptr< T >( pt, static_cast< T* >( pv ) );
+}
+
+template< class T, class A1, class A2, class A3, class A4, class A5, class A6, class A7, class A8 >
+boost::shared_ptr< T > make_shared( A1 const & a1, A2 const & a2, A3 const & a3, A4 const & a4, A5 const & a5, A6 const & a6, A7 const & a7, A8 const & a8 )
+{
+ boost::shared_ptr< T > pt( static_cast< T* >( 0 ), detail::sp_ms_deleter< T >() );
+
+ detail::sp_ms_deleter< T > * pd = boost::get_deleter< detail::sp_ms_deleter< T > >( pt );
+
+ void * pv = pd->address();
+
+ new( pv ) T( a1, a2, a3, a4, a5, a6, a7, a8 );
+ pd->set_initialized();
+
+ return boost::shared_ptr< T >( pt, static_cast< T* >( pv ) );
+}
+
+template< class T, class A, class A1, class A2, class A3, class A4, class A5, class A6, class A7, class A8 >
+boost::shared_ptr< T > allocate_shared( A const & a, A1 const & a1, A2 const & a2, A3 const & a3, A4 const & a4, A5 const & a5, A6 const & a6, A7 const & a7, A8 const & a8 )
+{
+ boost::shared_ptr< T > pt( static_cast< T* >( 0 ), detail::sp_ms_deleter< T >(), a );
+
+ detail::sp_ms_deleter< T > * pd = boost::get_deleter< detail::sp_ms_deleter< T > >( pt );
+
+ void * pv = pd->address();
+
+ new( pv ) T( a1, a2, a3, a4, a5, a6, a7, a8 );
+ pd->set_initialized();
+
+ return boost::shared_ptr< T >( pt, static_cast< T* >( pv ) );
+}
+
+template< class T, class A1, class A2, class A3, class A4, class A5, class A6, class A7, class A8, class A9 >
+boost::shared_ptr< T > make_shared( A1 const & a1, A2 const & a2, A3 const & a3, A4 const & a4, A5 const & a5, A6 const & a6, A7 const & a7, A8 const & a8, A9 const & a9 )
+{
+ boost::shared_ptr< T > pt( static_cast< T* >( 0 ), detail::sp_ms_deleter< T >() );
+
+ detail::sp_ms_deleter< T > * pd = boost::get_deleter< detail::sp_ms_deleter< T > >( pt );
+
+ void * pv = pd->address();
+
+ new( pv ) T( a1, a2, a3, a4, a5, a6, a7, a8, a9 );
+ pd->set_initialized();
+
+ return boost::shared_ptr< T >( pt, static_cast< T* >( pv ) );
+}
+
+template< class T, class A, class A1, class A2, class A3, class A4, class A5, class A6, class A7, class A8, class A9 >
+boost::shared_ptr< T > allocate_shared( A const & a, A1 const & a1, A2 const & a2, A3 const & a3, A4 const & a4, A5 const & a5, A6 const & a6, A7 const & a7, A8 const & a8, A9 const & a9 )
+{
+ boost::shared_ptr< T > pt( static_cast< T* >( 0 ), detail::sp_ms_deleter< T >(), a );
+
+ detail::sp_ms_deleter< T > * pd = boost::get_deleter< detail::sp_ms_deleter< T > >( pt );
+
+ void * pv = pd->address();
+
+ new( pv ) T( a1, a2, a3, a4, a5, a6, a7, a8, a9 );
+ pd->set_initialized();
+
+ return boost::shared_ptr< T >( pt, static_cast< T* >( pv ) );
+}
+
+#endif
+
+} // namespace boost
+
+#endif // #ifndef BOOST_MAKE_SHARED_HPP_INCLUDED
Modified: trunk/boost/type_traits/type_with_alignment.hpp
==============================================================================
--- trunk/boost/type_traits/type_with_alignment.hpp (original)
+++ trunk/boost/type_traits/type_with_alignment.hpp 2008-05-01 12:50:39 EDT (Thu, 01 May 2008)
@@ -242,7 +242,7 @@
BOOST_TT_AUX_BOOL_TRAIT_IMPL_SPEC1(is_pod,::boost::align::a32,true)
}
#endif
-#if defined(BOOST_MSVC) || (defined(BOOST_INTEL) && defined(_MSC_VER))
+#if (defined(BOOST_MSVC) || (defined(BOOST_INTEL) && defined(_MSC_VER))) && _MSC_VER >= 1300
//
// MSVC supports types which have alignments greater than the normal
// maximum: these are used for example in the types __m64 and __m128
Modified: trunk/libs/smart_ptr/test/Jamfile.v2
==============================================================================
--- trunk/libs/smart_ptr/test/Jamfile.v2 (original)
+++ trunk/libs/smart_ptr/test/Jamfile.v2 2008-05-01 12:50:39 EDT (Thu, 01 May 2008)
@@ -45,5 +45,6 @@
[ run spinlock_pool_test.cpp ]
[ run sp_accept_owner_test.cpp ]
[ run sp_atomic_test.cpp ]
+ [ run make_shared_test.cpp ]
;
}
Added: trunk/libs/smart_ptr/test/make_shared_test.cpp
==============================================================================
--- (empty file)
+++ trunk/libs/smart_ptr/test/make_shared_test.cpp 2008-05-01 12:50:39 EDT (Thu, 01 May 2008)
@@ -0,0 +1,334 @@
+// make_shared_test.cpp
+//
+// Copyright (c) 2007, 2008 Peter Dimov
+//
+// Distributed under the Boost Software License, Version 1.0.
+// See accompanying file LICENSE_1_0.txt or copy at
+// http://www.boost.org/LICENSE_1_0.txt
+
+#include <boost/detail/lightweight_test.hpp>
+#include <boost/make_shared.hpp>
+#include <boost/shared_ptr.hpp>
+#include <boost/weak_ptr.hpp>
+
+class X
+{
+private:
+
+ X( X const & );
+ X & operator=( X const & );
+
+public:
+
+ static int instances;
+
+ int v;
+
+ explicit X( int a1 = 0, int a2 = 0, int a3 = 0, int a4 = 0, int a5 = 0, int a6 = 0, int a7 = 0, int a8 = 0, int a9 = 0 ): v( a1+a2+a3+a4+a5+a6+a7+a8+a9 )
+ {
+ ++instances;
+ }
+
+ ~X()
+ {
+ --instances;
+ }
+};
+
+int X::instances = 0;
+
+int main()
+{
+ {
+ boost::shared_ptr< int > pi = boost::make_shared< int >();
+
+ BOOST_TEST( pi.get() != 0 );
+ BOOST_TEST( *pi == 0 );
+ }
+
+ {
+ boost::shared_ptr< int > pi = boost::allocate_shared< int >( std::allocator<int>() );
+
+ BOOST_TEST( pi.get() != 0 );
+ BOOST_TEST( *pi == 0 );
+ }
+
+ {
+ boost::shared_ptr< int > pi = boost::make_shared< int >( 5 );
+
+ BOOST_TEST( pi.get() != 0 );
+ BOOST_TEST( *pi == 5 );
+ }
+
+ {
+ boost::shared_ptr< int > pi = boost::allocate_shared< int >( std::allocator<int>(), 5 );
+
+ BOOST_TEST( pi.get() != 0 );
+ BOOST_TEST( *pi == 5 );
+ }
+
+ BOOST_TEST( X::instances == 0 );
+
+ {
+ boost::shared_ptr< X > pi = boost::make_shared< 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::allocate_shared< 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::make_shared< X >( 1 );
+ boost::weak_ptr<X> wp( pi );
+
+ BOOST_TEST( X::instances == 1 );
+ BOOST_TEST( pi.get() != 0 );
+ BOOST_TEST( pi->v == 1 );
+
+ pi.reset();
+
+ BOOST_TEST( X::instances == 0 );
+ }
+
+ {
+ boost::shared_ptr< X > pi = boost::allocate_shared< X >( std::allocator<void>(), 1 );
+ boost::weak_ptr<X> wp( pi );
+
+ BOOST_TEST( X::instances == 1 );
+ BOOST_TEST( pi.get() != 0 );
+ BOOST_TEST( pi->v == 1 );
+
+ pi.reset();
+
+ BOOST_TEST( X::instances == 0 );
+ }
+
+ {
+ boost::shared_ptr< X > pi = boost::make_shared< X >( 1, 2 );
+ boost::weak_ptr<X> wp( pi );
+
+ BOOST_TEST( X::instances == 1 );
+ BOOST_TEST( pi.get() != 0 );
+ BOOST_TEST( pi->v == 1+2 );
+
+ pi.reset();
+
+ BOOST_TEST( X::instances == 0 );
+ }
+
+ {
+ boost::shared_ptr< X > pi = boost::allocate_shared< X >( std::allocator<void>(), 1, 2 );
+ boost::weak_ptr<X> wp( pi );
+
+ BOOST_TEST( X::instances == 1 );
+ BOOST_TEST( pi.get() != 0 );
+ BOOST_TEST( pi->v == 1+2 );
+
+ pi.reset();
+
+ BOOST_TEST( X::instances == 0 );
+ }
+
+ {
+ boost::shared_ptr< X > pi = boost::make_shared< X >( 1, 2, 3 );
+ boost::weak_ptr<X> wp( pi );
+
+ BOOST_TEST( X::instances == 1 );
+ BOOST_TEST( pi.get() != 0 );
+ BOOST_TEST( pi->v == 1+2+3 );
+
+ pi.reset();
+
+ BOOST_TEST( X::instances == 0 );
+ }
+
+ {
+ boost::shared_ptr< X > pi = boost::allocate_shared< X >( std::allocator<void>(), 1, 2, 3 );
+ boost::weak_ptr<X> wp( pi );
+
+ BOOST_TEST( X::instances == 1 );
+ BOOST_TEST( pi.get() != 0 );
+ BOOST_TEST( pi->v == 1+2+3 );
+
+ pi.reset();
+
+ BOOST_TEST( X::instances == 0 );
+ }
+
+ {
+ boost::shared_ptr< X > pi = boost::make_shared< X >( 1, 2, 3, 4 );
+ boost::weak_ptr<X> wp( pi );
+
+ BOOST_TEST( X::instances == 1 );
+ BOOST_TEST( pi.get() != 0 );
+ BOOST_TEST( pi->v == 1+2+3+4 );
+
+ pi.reset();
+
+ BOOST_TEST( X::instances == 0 );
+ }
+
+ {
+ boost::shared_ptr< X > pi = boost::allocate_shared< X >( std::allocator<void>(), 1, 2, 3, 4 );
+ boost::weak_ptr<X> wp( pi );
+
+ BOOST_TEST( X::instances == 1 );
+ BOOST_TEST( pi.get() != 0 );
+ BOOST_TEST( pi->v == 1+2+3+4 );
+
+ pi.reset();
+
+ BOOST_TEST( X::instances == 0 );
+ }
+
+ {
+ boost::shared_ptr< X > pi = boost::make_shared< X >( 1, 2, 3, 4, 5 );
+ boost::weak_ptr<X> wp( pi );
+
+ BOOST_TEST( X::instances == 1 );
+ BOOST_TEST( pi.get() != 0 );
+ BOOST_TEST( pi->v == 1+2+3+4+5 );
+
+ pi.reset();
+
+ BOOST_TEST( X::instances == 0 );
+ }
+
+ {
+ boost::shared_ptr< X > pi = boost::allocate_shared< X >( std::allocator<void>(), 1, 2, 3, 4, 5 );
+ boost::weak_ptr<X> wp( pi );
+
+ BOOST_TEST( X::instances == 1 );
+ BOOST_TEST( pi.get() != 0 );
+ BOOST_TEST( pi->v == 1+2+3+4+5 );
+
+ pi.reset();
+
+ BOOST_TEST( X::instances == 0 );
+ }
+
+ {
+ boost::shared_ptr< X > pi = boost::make_shared< X >( 1, 2, 3, 4, 5, 6 );
+ boost::weak_ptr<X> wp( pi );
+
+ BOOST_TEST( X::instances == 1 );
+ BOOST_TEST( pi.get() != 0 );
+ BOOST_TEST( pi->v == 1+2+3+4+5+6 );
+
+ pi.reset();
+
+ BOOST_TEST( X::instances == 0 );
+ }
+
+ {
+ boost::shared_ptr< X > pi = boost::allocate_shared< X >( std::allocator<void>(), 1, 2, 3, 4, 5, 6 );
+ boost::weak_ptr<X> wp( pi );
+
+ BOOST_TEST( X::instances == 1 );
+ BOOST_TEST( pi.get() != 0 );
+ BOOST_TEST( pi->v == 1+2+3+4+5+6 );
+
+ pi.reset();
+
+ BOOST_TEST( X::instances == 0 );
+ }
+
+ {
+ boost::shared_ptr< X > pi = boost::make_shared< X >( 1, 2, 3, 4, 5, 6, 7 );
+ boost::weak_ptr<X> wp( pi );
+
+ BOOST_TEST( X::instances == 1 );
+ BOOST_TEST( pi.get() != 0 );
+ BOOST_TEST( pi->v == 1+2+3+4+5+6+7 );
+
+ pi.reset();
+
+ BOOST_TEST( X::instances == 0 );
+ }
+
+ {
+ boost::shared_ptr< X > pi = boost::allocate_shared< X >( std::allocator<void>(), 1, 2, 3, 4, 5, 6, 7 );
+ boost::weak_ptr<X> wp( pi );
+
+ BOOST_TEST( X::instances == 1 );
+ BOOST_TEST( pi.get() != 0 );
+ BOOST_TEST( pi->v == 1+2+3+4+5+6+7 );
+
+ pi.reset();
+
+ BOOST_TEST( X::instances == 0 );
+ }
+
+ {
+ boost::shared_ptr< X > pi = boost::make_shared< X >( 1, 2, 3, 4, 5, 6, 7, 8 );
+ boost::weak_ptr<X> wp( pi );
+
+ BOOST_TEST( X::instances == 1 );
+ BOOST_TEST( pi.get() != 0 );
+ BOOST_TEST( pi->v == 1+2+3+4+5+6+7+8 );
+
+ pi.reset();
+
+ BOOST_TEST( X::instances == 0 );
+ }
+
+ {
+ boost::shared_ptr< X > pi = boost::allocate_shared< X >( std::allocator<void>(), 1, 2, 3, 4, 5, 6, 7, 8 );
+ boost::weak_ptr<X> wp( pi );
+
+ BOOST_TEST( X::instances == 1 );
+ BOOST_TEST( pi.get() != 0 );
+ BOOST_TEST( pi->v == 1+2+3+4+5+6+7+8 );
+
+ pi.reset();
+
+ BOOST_TEST( X::instances == 0 );
+ }
+
+ {
+ boost::shared_ptr< X > pi = boost::make_shared< X >( 1, 2, 3, 4, 5, 6, 7, 8, 9 );
+ boost::weak_ptr<X> wp( pi );
+
+ BOOST_TEST( X::instances == 1 );
+ BOOST_TEST( pi.get() != 0 );
+ BOOST_TEST( pi->v == 1+2+3+4+5+6+7+8+9 );
+
+ pi.reset();
+
+ BOOST_TEST( X::instances == 0 );
+ }
+
+ {
+ boost::shared_ptr< X > pi = boost::allocate_shared< X >( std::allocator<void>(), 1, 2, 3, 4, 5, 6, 7, 8, 9 );
+ boost::weak_ptr<X> wp( pi );
+
+ BOOST_TEST( X::instances == 1 );
+ BOOST_TEST( pi.get() != 0 );
+ BOOST_TEST( pi->v == 1+2+3+4+5+6+7+8+9 );
+
+ pi.reset();
+
+ BOOST_TEST( X::instances == 0 );
+ }
+
+ return boost::report_errors();
+}
Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk