Compare commits

..

1 Commits

Author SHA1 Message Date
Beman Dawes
48b9c28570 Release 1.29.0 beta 1
[SVN r52601]
2009-04-26 12:32:35 +00:00
31 changed files with 143 additions and 1065 deletions

30
CMakeLists.txt Normal file
View File

@@ -0,0 +1,30 @@
#----------------------------------------------------------------------------
# This file was automatically generated from the original CMakeLists.txt file
# Add a variable to hold the headers for the library
set (lib_headers
enable_shared_from_this.hpp
pointer_cast.hpp
scoped_array.hpp
scoped_ptr.hpp
shared_array.hpp
shared_ptr.hpp
weak_ptr.hpp
)
# Add a library target to the build system
boost_library_project(
smart_ptr
# SRCDIRS
TESTDIRS test
HEADERS ${lib_headers}
# DOCDIRS
DESCRIPTION "Five smart pointer class templates."
MODULARIZED
AUTHORS "Greg Colvin"
"Beman Dawes <bdawes -at- acm.org>"
"Peter Dimov <pdimov -at- mmltd.net>"
"Darin Adler"
# MAINTAINERS
)

View File

@@ -29,24 +29,20 @@
and <STRONG>shared_ptr&lt;T const&gt;</STRONG>, depending on constness, to <STRONG>this</STRONG>.</P>
<h3><a name="Example">Example</a></h3>
<pre>
#include &lt;boost/enable_shared_from_this.hpp&gt;
#include &lt;boost/shared_ptr.hpp&gt;
#include &lt;cassert&gt;
class Y: public boost::enable_shared_from_this&lt;Y&gt;
class Y: public enable_shared_from_this&lt;Y&gt;
{
public:
boost::shared_ptr&lt;Y&gt; f()
shared_ptr&lt;Y&gt; f()
{
return shared_from_this();
}
};
}
int main()
{
boost::shared_ptr&lt;Y&gt; p(new Y);
boost::shared_ptr&lt;Y&gt; q = p-&gt;f();
shared_ptr&lt;Y&gt; p(new Y);
shared_ptr&lt;Y&gt; q = p-&gt;f();
assert(p == q);
assert(!(p &lt; q || q &lt; p)); // p and q must share ownership
}

View File

@@ -19,66 +19,20 @@
#if defined( BOOST_NO_TYPEID )
#include <boost/current_function.hpp>
#include <functional>
namespace boost
{
namespace detail
{
class sp_typeinfo
{
private:
sp_typeinfo( sp_typeinfo const& );
sp_typeinfo& operator=( sp_typeinfo const& );
char const * name_;
public:
explicit sp_typeinfo( char const * name ): name_( name )
{
}
bool operator==( sp_typeinfo const& rhs ) const
{
return this == &rhs;
}
bool operator!=( sp_typeinfo const& rhs ) const
{
return this != &rhs;
}
bool before( sp_typeinfo const& rhs ) const
{
return std::less< sp_typeinfo const* >()( this, &rhs );
}
char const* name() const
{
return name_;
}
};
typedef void* sp_typeinfo;
template<class T> struct sp_typeid_
{
static sp_typeinfo ti_;
static char const * name()
{
return BOOST_CURRENT_FUNCTION;
}
static char v_;
};
template<class T> sp_typeinfo sp_typeid_< T >::ti_ = sp_typeid_< T >::name();
template<class T> struct sp_typeid_< T & >: sp_typeid_< T >
{
};
template<class T> char sp_typeid_< T >::v_;
template<class T> struct sp_typeid_< T const >: sp_typeid_< T >
{
@@ -96,7 +50,7 @@ template<class T> struct sp_typeid_< T const volatile >: sp_typeid_< T >
} // namespace boost
#define BOOST_SP_TYPEID(T) (boost::detail::sp_typeid_<T>::ti_)
#define BOOST_SP_TYPEID(T) (&boost::detail::sp_typeid_<T>::v_)
#else

View File

@@ -11,7 +11,7 @@
//
// Defines enum boost::memory_order per the C++0x working draft
//
// Copyright (c) 2008, 2009 Peter Dimov
// Copyright (c) 2008 Peter Dimov
//
// Distributed under the Boost Software License, Version 1.0.
// See accompanying file LICENSE_1_0.txt or copy at
@@ -21,31 +21,13 @@
namespace boost
{
//
// Enum values are chosen so that code that needs to insert
// a trailing fence for acquire semantics can use a single
// test such as:
//
// if( mo & memory_order_acquire ) { ...fence... }
//
// For leading fences one can use:
//
// if( mo & memory_order_release ) { ...fence... }
//
// Architectures such as Alpha that need a fence on consume
// can use:
//
// if( mo & ( memory_order_acquire | memory_order_consume ) ) { ...fence... }
//
enum memory_order
{
memory_order_relaxed = 0,
memory_order_acquire = 1,
memory_order_release = 2,
memory_order_acq_rel = 3, // acquire | release
memory_order_seq_cst = 7, // acq_rel | 4
memory_order_consume = 8
memory_order_seq_cst = 7 // acq_rel | 4
};
} // namespace boost

View File

@@ -17,7 +17,6 @@
// http://www.boost.org/LICENSE_1_0.txt)
//
#include <boost/assert.hpp>
#include <pthread.h>
namespace boost
@@ -43,15 +42,15 @@ public:
// HPUX 10.20 / DCE has a nonstandard pthread_mutex_init
#if defined(__hpux) && defined(_DECTHREADS_)
BOOST_VERIFY( pthread_mutex_init( &m_, pthread_mutexattr_default ) == 0 );
pthread_mutex_init(&m_, pthread_mutexattr_default);
#else
BOOST_VERIFY( pthread_mutex_init( &m_, 0 ) == 0 );
pthread_mutex_init(&m_, 0);
#endif
}
~lightweight_mutex()
{
BOOST_VERIFY( pthread_mutex_destroy( &m_ ) == 0 );
pthread_mutex_destroy(&m_);
}
class scoped_lock;
@@ -70,12 +69,12 @@ public:
scoped_lock(lightweight_mutex & m): m_(m.m_)
{
BOOST_VERIFY( pthread_mutex_lock( &m_ ) == 0 );
pthread_mutex_lock(&m_);
}
~scoped_lock()
{
BOOST_VERIFY( pthread_mutex_unlock( &m_ ) == 0 );
pthread_mutex_unlock(&m_);
}
};
};

View File

@@ -74,9 +74,8 @@ template<unsigned size, unsigned align_> struct allocator_impl
static lightweight_mutex & mutex()
{
static freeblock< sizeof( lightweight_mutex ), boost::alignment_of< lightweight_mutex >::value > fbm;
static lightweight_mutex * pm = new( &fbm ) lightweight_mutex;
return *pm;
static lightweight_mutex m;
return m;
}
static lightweight_mutex * mutex_init;

View File

@@ -333,20 +333,6 @@ public:
if(pi_ != 0) pi_->weak_add_ref();
}
// Move support
#if defined( BOOST_HAS_RVALUE_REFS )
weak_count(weak_count && r): pi_(r.pi_) // nothrow
#if defined(BOOST_SP_ENABLE_DEBUG_HOOKS)
, id_(weak_count_id)
#endif
{
r.pi_ = 0;
}
#endif
~weak_count() // nothrow
{
if(pi_ != 0) pi_->weak_release();

View File

@@ -25,7 +25,7 @@
# define BOOST_SP_NO_SP_CONVERTIBLE
#endif
#if !defined( BOOST_SP_NO_SP_CONVERTIBLE ) && defined( __BORLANDC__ ) && ( __BORLANDC__ < 0x630 )
#if !defined( BOOST_SP_NO_SP_CONVERTIBLE ) && defined( __BORLANDC__ ) && ( __BORLANDC__ <= 0x610 )
# define BOOST_SP_NO_SP_CONVERTIBLE
#endif
@@ -45,7 +45,7 @@ template< class Y, class T > struct sp_convertible
static yes f( T* );
static no f( ... );
enum _vt { value = sizeof( (f)( static_cast<Y*>(0) ) ) == sizeof(yes) };
enum _vt { value = sizeof( f( (Y*)0 ) ) == sizeof(yes) };
};
struct sp_empty

View File

@@ -30,9 +30,9 @@ namespace detail
inline int32_t compare_and_swap( int32_t * dest_, int32_t compare_, int32_t swap_ )
{
__asm__ __volatile__( "cas [%1], %2, %0"
: "+r" (swap_)
: "r" (dest_), "r" (compare_)
__asm__ __volatile__( "cas %0, %2, %1"
: "+m" (*dest_), "+r" (swap_)
: "r" (compare_)
: "memory" );
return swap_;

View File

@@ -40,7 +40,7 @@
#undef BOOST_SP_HAS_SYNC
#endif
#if defined( __INTEL_COMPILER ) && !defined( __ia64__ ) && ( __INTEL_COMPILER < 1100 )
#if defined( __INTEL_COMPILER ) && !defined( __ia64__ )
#undef BOOST_SP_HAS_SYNC
#endif

View File

@@ -55,7 +55,7 @@ namespace detail
{
#if !defined( BOOST_USE_WINDOWS_H )
extern "C" void __stdcall Sleep( unsigned long ms );
extern "C" void __stdcall Sleep( unsigned ms );
#endif
inline void yield( unsigned k )

View File

@@ -1,132 +0,0 @@
#ifndef BOOST_ENABLE_SHARED_FROM_THIS2_HPP_INCLUDED
#define BOOST_ENABLE_SHARED_FROM_THIS2_HPP_INCLUDED
//
// enable_shared_from_this2.hpp
//
// Copyright 2002, 2009 Peter Dimov
// Copyright 2008 Frank Mori Hess
//
// 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/config.hpp>
#include <boost/shared_ptr.hpp>
#include <boost/assert.hpp>
#include <boost/detail/workaround.hpp>
namespace boost
{
namespace detail
{
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< class T> void operator()( T* )
{
BOOST_ASSERT( deleter_.use_count() <= 1 );
deleter_.reset();
}
};
} // namespace detail
template< class T > class enable_shared_from_this2
{
protected:
enable_shared_from_this2()
{
}
enable_shared_from_this2( enable_shared_from_this2 const & )
{
}
enable_shared_from_this2 & operator=( enable_shared_from_this2 const & )
{
return *this;
}
~enable_shared_from_this2()
{
BOOST_ASSERT( shared_this_.use_count() <= 1 ); // make sure no dangling shared_ptr objects exist
}
private:
mutable weak_ptr<T> weak_this_;
mutable shared_ptr<T> shared_this_;
public:
shared_ptr<T> shared_from_this()
{
init_weak_once();
return shared_ptr<T>( weak_this_ );
}
shared_ptr<T const> shared_from_this() const
{
init_weak_once();
return shared_ptr<T>( weak_this_ );
}
private:
void init_weak_once() const
{
if( weak_this_._empty() )
{
shared_this_.reset( static_cast< T* >( 0 ), detail::esft2_deleter_wrapper() );
weak_this_ = shared_this_;
}
}
public: // actually private, but avoids compiler template friendship issues
// Note: invoked automatically by shared_ptr; do not call
template<class X, class Y> void _internal_accept_owner( shared_ptr<X> * ppx, Y * py ) const
{
BOOST_ASSERT( ppx != 0 );
if( weak_this_.use_count() == 0 )
{
weak_this_ = shared_ptr<T>( *ppx, py );
}
else if( shared_this_.use_count() != 0 )
{
BOOST_ASSERT( ppx->unique() ); // no weak_ptrs should exist either, but there's no way to check that
detail::esft2_deleter_wrapper * pd = boost::get_deleter<detail::esft2_deleter_wrapper>( shared_this_ );
BOOST_ASSERT( pd != 0 );
pd->set_deleter( *ppx );
ppx->reset( shared_this_, ppx->get() );
shared_this_.reset();
}
}
};
} // namespace boost
#endif // #ifndef BOOST_ENABLE_SHARED_FROM_THIS2_HPP_INCLUDED

View File

@@ -77,7 +77,7 @@ public:
template<class U>
#if !defined( BOOST_SP_NO_SP_CONVERTIBLE )
intrusive_ptr( intrusive_ptr<U> const & rhs, typename boost::detail::sp_enable_if_convertible<U,T>::type = boost::detail::sp_empty() )
intrusive_ptr( intrusive_ptr<U> const & rhs, typename detail::sp_enable_if_convertible<U,T>::type = detail::sp_empty() )
#else
@@ -109,23 +109,6 @@ public:
return *this;
}
#endif
// Move support
#if defined( BOOST_HAS_RVALUE_REFS )
intrusive_ptr(intrusive_ptr && rhs): px( rhs.px )
{
rhs.px = 0;
}
intrusive_ptr & operator=(intrusive_ptr && rhs)
{
this_type( static_cast< intrusive_ptr && >( rhs ) ).swap(*this);
return *this;
}
#endif
intrusive_ptr & operator=(intrusive_ptr const & rhs)

View File

@@ -86,15 +86,11 @@ public:
}
};
#if defined( BOOST_HAS_RVALUE_REFS )
template< class T > T&& sp_forward( T & t )
template< class T > T forward( T t )
{
return static_cast< T&& >( t );
return t;
}
#endif
} // namespace detail
// Zero-argument versions
@@ -103,9 +99,9 @@ template< class T > T&& sp_forward( T & t )
template< class T > boost::shared_ptr< T > make_shared()
{
boost::shared_ptr< T > pt( static_cast< T* >( 0 ), boost::detail::sp_ms_deleter< T >() );
boost::shared_ptr< T > pt( static_cast< T* >( 0 ), detail::sp_ms_deleter< T >() );
boost::detail::sp_ms_deleter< T > * pd = boost::get_deleter< boost::detail::sp_ms_deleter< T > >( pt );
detail::sp_ms_deleter< T > * pd = boost::get_deleter< detail::sp_ms_deleter< T > >( pt );
void * pv = pd->address();
@@ -120,9 +116,9 @@ template< class T > boost::shared_ptr< T > make_shared()
template< class T, class A > boost::shared_ptr< T > allocate_shared( A const & a )
{
boost::shared_ptr< T > pt( static_cast< T* >( 0 ), boost::detail::sp_ms_deleter< T >(), a );
boost::shared_ptr< T > pt( static_cast< T* >( 0 ), detail::sp_ms_deleter< T >(), a );
boost::detail::sp_ms_deleter< T > * pd = boost::get_deleter< boost::detail::sp_ms_deleter< T > >( pt );
detail::sp_ms_deleter< T > * pd = boost::get_deleter< detail::sp_ms_deleter< T > >( pt );
void * pv = pd->address();
@@ -139,15 +135,15 @@ template< class T, class A > boost::shared_ptr< T > allocate_shared( A const & a
// Variadic templates, rvalue reference
template< class T, class Arg1, class... Args > boost::shared_ptr< T > make_shared( Arg1 && arg1, Args && ... args )
template< class T, class... Args > boost::shared_ptr< T > make_shared( Args && ... args )
{
boost::shared_ptr< T > pt( static_cast< T* >( 0 ), boost::detail::sp_ms_deleter< T >() );
boost::shared_ptr< T > pt( static_cast< T* >( 0 ), detail::sp_ms_deleter< T >() );
boost::detail::sp_ms_deleter< T > * pd = boost::get_deleter< boost::detail::sp_ms_deleter< T > >( pt );
detail::sp_ms_deleter< T > * pd = boost::get_deleter< detail::sp_ms_deleter< T > >( pt );
void * pv = pd->address();
::new( pv ) T( boost::detail::sp_forward<Arg1>( arg1 ), boost::detail::sp_forward<Args>( args )... );
::new( pv ) T( detail::forward<Args>( args )... );
pd->set_initialized();
T * pt2 = static_cast< T* >( pv );
@@ -156,15 +152,15 @@ template< class T, class Arg1, class... Args > boost::shared_ptr< T > make_share
return boost::shared_ptr< T >( pt, pt2 );
}
template< class T, class A, class Arg1, class... Args > boost::shared_ptr< T > allocate_shared( A const & a, Arg1 && arg1, Args && ... args )
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 ), boost::detail::sp_ms_deleter< T >(), a );
boost::shared_ptr< T > pt( static_cast< T* >( 0 ), detail::sp_ms_deleter< T >(), a );
boost::detail::sp_ms_deleter< T > * pd = boost::get_deleter< boost::detail::sp_ms_deleter< T > >( pt );
detail::sp_ms_deleter< T > * pd = boost::get_deleter< detail::sp_ms_deleter< T > >( pt );
void * pv = pd->address();
::new( pv ) T( boost::detail::sp_forward<Arg1>( arg1 ), boost::detail::sp_forward<Args>( args )... );
::new( pv ) T( detail::forward<Args>( args )... );
pd->set_initialized();
T * pt2 = static_cast< T* >( pv );
@@ -180,9 +176,9 @@ template< class T, class A, class Arg1, class... Args > boost::shared_ptr< T > a
template< class T, class A1 >
boost::shared_ptr< T > make_shared( A1 const & a1 )
{
boost::shared_ptr< T > pt( static_cast< T* >( 0 ), boost::detail::sp_ms_deleter< T >() );
boost::shared_ptr< T > pt( static_cast< T* >( 0 ), detail::sp_ms_deleter< T >() );
boost::detail::sp_ms_deleter< T > * pd = boost::get_deleter< boost::detail::sp_ms_deleter< T > >( pt );
detail::sp_ms_deleter< T > * pd = boost::get_deleter< detail::sp_ms_deleter< T > >( pt );
void * pv = pd->address();
@@ -198,9 +194,9 @@ boost::shared_ptr< T > make_shared( A1 const & a1 )
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 ), boost::detail::sp_ms_deleter< T >(), a );
boost::shared_ptr< T > pt( static_cast< T* >( 0 ), detail::sp_ms_deleter< T >(), a );
boost::detail::sp_ms_deleter< T > * pd = boost::get_deleter< boost::detail::sp_ms_deleter< T > >( pt );
detail::sp_ms_deleter< T > * pd = boost::get_deleter< detail::sp_ms_deleter< T > >( pt );
void * pv = pd->address();
@@ -216,9 +212,9 @@ boost::shared_ptr< T > allocate_shared( A const & a, A1 const & a1 )
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 ), boost::detail::sp_ms_deleter< T >() );
boost::shared_ptr< T > pt( static_cast< T* >( 0 ), detail::sp_ms_deleter< T >() );
boost::detail::sp_ms_deleter< T > * pd = boost::get_deleter< boost::detail::sp_ms_deleter< T > >( pt );
detail::sp_ms_deleter< T > * pd = boost::get_deleter< detail::sp_ms_deleter< T > >( pt );
void * pv = pd->address();
@@ -234,9 +230,9 @@ boost::shared_ptr< T > make_shared( A1 const & a1, A2 const & a2 )
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 ), boost::detail::sp_ms_deleter< T >(), a );
boost::shared_ptr< T > pt( static_cast< T* >( 0 ), detail::sp_ms_deleter< T >(), a );
boost::detail::sp_ms_deleter< T > * pd = boost::get_deleter< boost::detail::sp_ms_deleter< T > >( pt );
detail::sp_ms_deleter< T > * pd = boost::get_deleter< detail::sp_ms_deleter< T > >( pt );
void * pv = pd->address();
@@ -252,9 +248,9 @@ boost::shared_ptr< T > allocate_shared( A const & a, A1 const & a1, A2 const & a
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 ), boost::detail::sp_ms_deleter< T >() );
boost::shared_ptr< T > pt( static_cast< T* >( 0 ), detail::sp_ms_deleter< T >() );
boost::detail::sp_ms_deleter< T > * pd = boost::get_deleter< boost::detail::sp_ms_deleter< T > >( pt );
detail::sp_ms_deleter< T > * pd = boost::get_deleter< detail::sp_ms_deleter< T > >( pt );
void * pv = pd->address();
@@ -270,9 +266,9 @@ boost::shared_ptr< T > make_shared( A1 const & a1, A2 const & a2, A3 const & a3
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 ), boost::detail::sp_ms_deleter< T >(), a );
boost::shared_ptr< T > pt( static_cast< T* >( 0 ), detail::sp_ms_deleter< T >(), a );
boost::detail::sp_ms_deleter< T > * pd = boost::get_deleter< boost::detail::sp_ms_deleter< T > >( pt );
detail::sp_ms_deleter< T > * pd = boost::get_deleter< detail::sp_ms_deleter< T > >( pt );
void * pv = pd->address();
@@ -288,9 +284,9 @@ boost::shared_ptr< T > allocate_shared( A const & a, A1 const & a1, A2 const & a
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 ), boost::detail::sp_ms_deleter< T >() );
boost::shared_ptr< T > pt( static_cast< T* >( 0 ), detail::sp_ms_deleter< T >() );
boost::detail::sp_ms_deleter< T > * pd = boost::get_deleter< boost::detail::sp_ms_deleter< T > >( pt );
detail::sp_ms_deleter< T > * pd = boost::get_deleter< detail::sp_ms_deleter< T > >( pt );
void * pv = pd->address();
@@ -306,9 +302,9 @@ boost::shared_ptr< T > make_shared( A1 const & a1, A2 const & a2, A3 const & a3,
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 ), boost::detail::sp_ms_deleter< T >(), a );
boost::shared_ptr< T > pt( static_cast< T* >( 0 ), detail::sp_ms_deleter< T >(), a );
boost::detail::sp_ms_deleter< T > * pd = boost::get_deleter< boost::detail::sp_ms_deleter< T > >( pt );
detail::sp_ms_deleter< T > * pd = boost::get_deleter< detail::sp_ms_deleter< T > >( pt );
void * pv = pd->address();
@@ -324,9 +320,9 @@ boost::shared_ptr< T > allocate_shared( A const & a, A1 const & a1, A2 const & a
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 ), boost::detail::sp_ms_deleter< T >() );
boost::shared_ptr< T > pt( static_cast< T* >( 0 ), detail::sp_ms_deleter< T >() );
boost::detail::sp_ms_deleter< T > * pd = boost::get_deleter< boost::detail::sp_ms_deleter< T > >( pt );
detail::sp_ms_deleter< T > * pd = boost::get_deleter< detail::sp_ms_deleter< T > >( pt );
void * pv = pd->address();
@@ -342,9 +338,9 @@ boost::shared_ptr< T > make_shared( A1 const & a1, A2 const & a2, A3 const & a3,
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 ), boost::detail::sp_ms_deleter< T >(), a );
boost::shared_ptr< T > pt( static_cast< T* >( 0 ), detail::sp_ms_deleter< T >(), a );
boost::detail::sp_ms_deleter< T > * pd = boost::get_deleter< boost::detail::sp_ms_deleter< T > >( pt );
detail::sp_ms_deleter< T > * pd = boost::get_deleter< detail::sp_ms_deleter< T > >( pt );
void * pv = pd->address();
@@ -360,9 +356,9 @@ boost::shared_ptr< T > allocate_shared( A const & a, A1 const & a1, A2 const & a
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 ), boost::detail::sp_ms_deleter< T >() );
boost::shared_ptr< T > pt( static_cast< T* >( 0 ), detail::sp_ms_deleter< T >() );
boost::detail::sp_ms_deleter< T > * pd = boost::get_deleter< boost::detail::sp_ms_deleter< T > >( pt );
detail::sp_ms_deleter< T > * pd = boost::get_deleter< detail::sp_ms_deleter< T > >( pt );
void * pv = pd->address();
@@ -378,9 +374,9 @@ boost::shared_ptr< T > make_shared( A1 const & a1, A2 const & a2, A3 const & a3,
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 ), boost::detail::sp_ms_deleter< T >(), a );
boost::shared_ptr< T > pt( static_cast< T* >( 0 ), detail::sp_ms_deleter< T >(), a );
boost::detail::sp_ms_deleter< T > * pd = boost::get_deleter< boost::detail::sp_ms_deleter< T > >( pt );
detail::sp_ms_deleter< T > * pd = boost::get_deleter< detail::sp_ms_deleter< T > >( pt );
void * pv = pd->address();
@@ -396,9 +392,9 @@ boost::shared_ptr< T > allocate_shared( A const & a, A1 const & a1, A2 const & a
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 ), boost::detail::sp_ms_deleter< T >() );
boost::shared_ptr< T > pt( static_cast< T* >( 0 ), detail::sp_ms_deleter< T >() );
boost::detail::sp_ms_deleter< T > * pd = boost::get_deleter< boost::detail::sp_ms_deleter< T > >( pt );
detail::sp_ms_deleter< T > * pd = boost::get_deleter< detail::sp_ms_deleter< T > >( pt );
void * pv = pd->address();
@@ -414,9 +410,9 @@ boost::shared_ptr< T > make_shared( A1 const & a1, A2 const & a2, A3 const & a3,
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 ), boost::detail::sp_ms_deleter< T >(), a );
boost::shared_ptr< T > pt( static_cast< T* >( 0 ), detail::sp_ms_deleter< T >(), a );
boost::detail::sp_ms_deleter< T > * pd = boost::get_deleter< boost::detail::sp_ms_deleter< T > >( pt );
detail::sp_ms_deleter< T > * pd = boost::get_deleter< detail::sp_ms_deleter< T > >( pt );
void * pv = pd->address();
@@ -432,9 +428,9 @@ boost::shared_ptr< T > allocate_shared( A const & a, A1 const & a1, A2 const & a
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 ), boost::detail::sp_ms_deleter< T >() );
boost::shared_ptr< T > pt( static_cast< T* >( 0 ), detail::sp_ms_deleter< T >() );
boost::detail::sp_ms_deleter< T > * pd = boost::get_deleter< boost::detail::sp_ms_deleter< T > >( pt );
detail::sp_ms_deleter< T > * pd = boost::get_deleter< detail::sp_ms_deleter< T > >( pt );
void * pv = pd->address();
@@ -450,9 +446,9 @@ boost::shared_ptr< T > make_shared( A1 const & a1, A2 const & a2, A3 const & a3,
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 ), boost::detail::sp_ms_deleter< T >(), a );
boost::shared_ptr< T > pt( static_cast< T* >( 0 ), detail::sp_ms_deleter< T >(), a );
boost::detail::sp_ms_deleter< T > * pd = boost::get_deleter< boost::detail::sp_ms_deleter< T > >( pt );
detail::sp_ms_deleter< T > * pd = boost::get_deleter< detail::sp_ms_deleter< T > >( pt );
void * pv = pd->address();
@@ -468,9 +464,9 @@ boost::shared_ptr< T > allocate_shared( A const & a, A1 const & a1, A2 const & a
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 ), boost::detail::sp_ms_deleter< T >() );
boost::shared_ptr< T > pt( static_cast< T* >( 0 ), detail::sp_ms_deleter< T >() );
boost::detail::sp_ms_deleter< T > * pd = boost::get_deleter< boost::detail::sp_ms_deleter< T > >( pt );
detail::sp_ms_deleter< T > * pd = boost::get_deleter< detail::sp_ms_deleter< T > >( pt );
void * pv = pd->address();
@@ -486,9 +482,9 @@ boost::shared_ptr< T > make_shared( A1 const & a1, A2 const & a2, A3 const & a3,
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 ), boost::detail::sp_ms_deleter< T >(), a );
boost::shared_ptr< T > pt( static_cast< T* >( 0 ), detail::sp_ms_deleter< T >(), a );
boost::detail::sp_ms_deleter< T > * pd = boost::get_deleter< boost::detail::sp_ms_deleter< T > >( pt );
detail::sp_ms_deleter< T > * pd = boost::get_deleter< detail::sp_ms_deleter< T > >( pt );
void * pv = pd->address();

View File

@@ -61,7 +61,6 @@ namespace 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;
namespace detail
{
@@ -110,14 +109,6 @@ template< class X, class Y, class T > inline void sp_enable_shared_from_this( bo
}
}
template< class X, class Y, class T > inline void sp_enable_shared_from_this( boost::shared_ptr<X> * ppx, Y const * py, boost::enable_shared_from_this2< T > const * pe )
{
if( pe != 0 )
{
pe->_internal_accept_owner( ppx, const_cast< Y* >( py ) );
}
}
#ifdef _MANAGED
// Avoid C4793, ... causes native code generation
@@ -228,7 +219,7 @@ public:
template<class Y>
#if !defined( BOOST_SP_NO_SP_CONVERTIBLE )
shared_ptr( shared_ptr<Y> const & r, typename boost::detail::sp_enable_if_convertible<Y,T>::type = boost::detail::sp_empty() )
shared_ptr( shared_ptr<Y> const & r, typename detail::sp_enable_if_convertible<Y,T>::type = detail::sp_empty() )
#else
@@ -353,7 +344,7 @@ public:
template<class Y>
#if !defined( BOOST_SP_NO_SP_CONVERTIBLE )
shared_ptr( shared_ptr<Y> && r, typename boost::detail::sp_enable_if_convertible<Y,T>::type = boost::detail::sp_empty() )
shared_ptr( shared_ptr<Y> && r, typename detail::sp_enable_if_convertible<Y,T>::type = detail::sp_empty() )
#else
@@ -448,7 +439,7 @@ public:
return pn < rhs.pn;
}
void * _internal_get_deleter( boost::detail::sp_typeinfo const & ti ) const
void * _internal_get_deleter( detail::sp_typeinfo const & ti ) const
{
return pn.get_deleter( ti );
}

View File

@@ -63,54 +63,22 @@ public:
template<class Y>
#if !defined( BOOST_SP_NO_SP_CONVERTIBLE )
weak_ptr( weak_ptr<Y> const & r, typename boost::detail::sp_enable_if_convertible<Y,T>::type = boost::detail::sp_empty() )
weak_ptr( weak_ptr<Y> const & r, typename detail::sp_enable_if_convertible<Y,T>::type = detail::sp_empty() )
#else
weak_ptr( weak_ptr<Y> const & r )
#endif
: px(r.lock().get()), pn(r.pn) // never throws
: pn(r.pn) // never throws
{
px = r.lock().get();
}
#if defined( BOOST_HAS_RVALUE_REFS )
template<class Y>
#if !defined( BOOST_SP_NO_SP_CONVERTIBLE )
weak_ptr( weak_ptr<Y> && r, typename boost::detail::sp_enable_if_convertible<Y,T>::type = boost::detail::sp_empty() )
#else
weak_ptr( weak_ptr<Y> && r )
#endif
: px( r.lock().get() ), pn( static_cast< boost::detail::weak_count && >( r.pn ) ) // never throws
{
r.px = 0;
}
// for better efficiency in the T == Y case
weak_ptr( weak_ptr && r ): px( r.px ), pn( static_cast< boost::detail::weak_count && >( r.pn ) ) // never throws
{
r.px = 0;
}
// for better efficiency in the T == Y case
weak_ptr & operator=( weak_ptr && r ) // never throws
{
this_type( static_cast< weak_ptr && >( r ) ).swap( *this );
return *this;
}
#endif
template<class Y>
#if !defined( BOOST_SP_NO_SP_CONVERTIBLE )
weak_ptr( shared_ptr<Y> const & r, typename boost::detail::sp_enable_if_convertible<Y,T>::type = boost::detail::sp_empty() )
weak_ptr( shared_ptr<Y> const & r, typename detail::sp_enable_if_convertible<Y,T>::type = detail::sp_empty() )
#else
@@ -131,17 +99,6 @@ public:
return *this;
}
#if defined( BOOST_HAS_RVALUE_REFS )
template<class Y>
weak_ptr & operator=( weak_ptr<Y> && r )
{
this_type( static_cast< weak_ptr<Y> && >( r ) ).swap( *this );
return *this;
}
#endif
template<class Y>
weak_ptr & operator=(shared_ptr<Y> const & r) // never throws
{
@@ -167,11 +124,6 @@ public:
return pn.use_count() == 0;
}
bool _empty() const // extension, not in std::weak_ptr
{
return pn.empty();
}
void reset() // never throws in 1.30+
{
this_type().swap(*this);

1
module.cmake Normal file
View File

@@ -0,0 +1 @@
boost_module(smart_ptr DEPENDS utility)

18
test/CMakeLists.txt Normal file
View File

@@ -0,0 +1,18 @@
boost_additional_test_dependencies(tokenizer BOOST_DEPENDS test intrusive)
boost_test_run(smart_ptr_test)
boost_test_run(shared_ptr_basic_test)
boost_test_run(shared_ptr_test)
boost_test_run(weak_ptr_test)
boost_test_run(shared_from_this_test)
boost_test_run(get_deleter_test)
boost_test_run(intrusive_ptr_test)
boost_test_run(atomic_count_test)
boost_test_run(lw_mutex_test)
boost_test_compile_fail(shared_ptr_assign_fail)
boost_test_compile_fail(shared_ptr_delete_fail)
boost_test_run(shared_ptr_alloc2_test)
boost_test_run(pointer_cast_test)
boost_test_compile(pointer_to_other_test)
boost_test_run(auto_ptr_rv_test)

View File

@@ -16,11 +16,9 @@ import testing ;
[ run shared_ptr_basic_test.cpp : : : <toolset>gcc:<cxxflags>-Wno-non-virtual-dtor ]
[ run shared_ptr_test.cpp : : : <toolset>gcc:<cxxflags>-Wno-non-virtual-dtor ]
[ run weak_ptr_test.cpp ]
[ run weak_ptr_move_test.cpp ]
[ run shared_from_this_test.cpp : : : <toolset>gcc:<cxxflags>-Wno-non-virtual-dtor ]
[ run get_deleter_test.cpp ]
[ run intrusive_ptr_test.cpp ]
[ run intrusive_ptr_move_test.cpp ]
[ run atomic_count_test.cpp ]
[ run lw_mutex_test.cpp ]
[ compile-fail shared_ptr_assign_fail.cpp ]
@@ -45,7 +43,6 @@ import testing ;
[ run spinlock_try_test.cpp : : : <threading>multi : spinlock_try_test.mt ]
[ run spinlock_pool_test.cpp ]
[ run make_shared_test.cpp ]
[ run make_shared_perfect_forwarding_test.cpp ]
[ run sp_convertible_test.cpp ]
[ run wp_convertible_test.cpp ]
[ run ip_convertible_test.cpp ]
@@ -59,10 +56,7 @@ import testing ;
[ run sp_recursive_assign2_test.cpp ]
[ run sp_recursive_assign_rv_test.cpp ]
[ run sp_recursive_assign2_rv_test.cpp ]
[ run esft_constructor_test.cpp ]
[ compile-fail auto_ptr_lv_fail.cpp ]
[ run atomic_count_test2.cpp ]
[ run sp_typeinfo_test.cpp ]
[ compile make_shared_fp_test.cpp ]
;
}

View File

@@ -1,169 +0,0 @@
//
// esft_constructor_test.cpp
//
// A test for the new enable_shared_from_this support for calling
// shared_from_this from constructors (that is, prior to the
// object's ownership being passed to an external shared_ptr).
//
// Copyright (c) 2008 Frank Mori Hess
// Copyright (c) 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/smart_ptr/enable_shared_from_this2.hpp>
#include <boost/shared_ptr.hpp>
#include <boost/weak_ptr.hpp>
#include <boost/detail/lightweight_test.hpp>
#include <memory>
class X: public boost::enable_shared_from_this2< X >
{
private:
int destroyed_;
int deleted_;
int expected_;
private:
X( X const& );
X& operator=( X const& );
public:
static int instances;
public:
explicit X( int expected, boost::shared_ptr<X> *early_px = 0 ): destroyed_( 0 ), deleted_( 0 ), expected_( expected )
{
++instances;
if( early_px ) *early_px = shared_from_this();
}
~X()
{
BOOST_TEST( deleted_ == expected_ );
BOOST_TEST( destroyed_ == 0 );
++destroyed_;
--instances;
}
typedef void (*deleter_type)( X* );
static void deleter( X * px )
{
++px->deleted_;
}
static void deleter2( X * px )
{
++px->deleted_;
delete px;
}
};
int X::instances = 0;
template<typename T, typename U>
bool are_shared_owners(const boost::shared_ptr<T> &a, const boost::shared_ptr<U> &b)
{
return !(a < b) && !(b < a);
}
struct Y: public boost::enable_shared_from_this2<Y>
{};
int main()
{
BOOST_TEST( X::instances == 0 );
{
boost::shared_ptr<X> early_px;
X* x = new X( 1, &early_px );
BOOST_TEST( early_px.use_count() > 0 );
BOOST_TEST( boost::get_deleter<X::deleter_type>(early_px) == 0 );
boost::shared_ptr<X> px( x, &X::deleter2 );
BOOST_TEST( early_px.use_count() == 2 && px.use_count() == 2 );
BOOST_TEST(are_shared_owners(early_px, px));
px.reset();
BOOST_TEST( early_px.use_count() == 1 );
BOOST_TEST( X::instances == 1 );
// X::deleter_type *pd = boost::get_deleter<X::deleter_type>(early_px);
// BOOST_TEST(pd && *pd == &X::deleter2 );
}
BOOST_TEST( X::instances == 0 );
{
boost::shared_ptr<X> early_px;
X* x = new X( 1, &early_px );
boost::weak_ptr<X> early_weak_px = early_px;
early_px.reset();
BOOST_TEST( !early_weak_px.expired() );
boost::shared_ptr<X> px( x, &X::deleter2 );
BOOST_TEST( px.use_count() == 1 );
BOOST_TEST( X::instances == 1 );
BOOST_TEST(are_shared_owners(early_weak_px.lock(), px));
px.reset();
BOOST_TEST( early_weak_px.expired() );
}
BOOST_TEST( X::instances == 0 );
{
boost::shared_ptr<X> early_px;
X x( 1, &early_px );
BOOST_TEST( early_px.use_count() > 0 );
boost::shared_ptr<X> px( &x, &X::deleter );
BOOST_TEST( early_px.use_count() == 2 && px.use_count() == 2 );
early_px.reset();
BOOST_TEST( px.use_count() == 1 );
BOOST_TEST( X::instances == 1 );
px.reset();
try
{
x.shared_from_this();
BOOST_ERROR("x did not throw bad_weak_ptr");
}
catch( const boost::bad_weak_ptr & )
{}
}
BOOST_TEST( X::instances == 0 );
{
boost::weak_ptr<X> early_weak_px;
{
boost::shared_ptr<X> early_px;
X x( 0, &early_px );
early_weak_px = early_px;
early_px.reset();
BOOST_TEST( !early_weak_px.expired() );
BOOST_TEST( X::instances == 1 );
}
BOOST_TEST( early_weak_px.expired() );
}
BOOST_TEST( X::instances == 0 );
{
boost::shared_ptr<Y> px(new Y());
Y y(*px);
px.reset();
try
{
y.shared_from_this();
}
catch( const boost::bad_weak_ptr & )
{
BOOST_ERROR("y threw bad_weak_ptr");
}
}
return boost::report_errors();
}

View File

@@ -1,184 +0,0 @@
#include <boost/config.hpp>
#if defined(BOOST_MSVC)
#pragma warning(disable: 4786) // identifier truncated in debug info
#pragma warning(disable: 4710) // function not inlined
#pragma warning(disable: 4711) // function selected for automatic inline expansion
#pragma warning(disable: 4514) // unreferenced inline removed
#pragma warning(disable: 4355) // 'this' : used in base member initializer list
#pragma warning(disable: 4511) // copy constructor could not be generated
#pragma warning(disable: 4512) // assignment operator could not be generated
#if (BOOST_MSVC >= 1310)
#pragma warning(disable: 4675) // resolved overload found with Koenig lookup
#endif
#endif
//
// intrusive_ptr_move_test.cpp
//
// Copyright (c) 2002-2005 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/intrusive_ptr.hpp>
#include <boost/detail/atomic_count.hpp>
#include <boost/config.hpp>
#include <algorithm>
#include <functional>
#if defined( BOOST_HAS_RVALUE_REFS )
namespace N
{
class base
{
private:
boost::detail::atomic_count use_count_;
base(base const &);
base & operator=(base const &);
protected:
base(): use_count_(0)
{
++instances;
}
virtual ~base()
{
--instances;
}
public:
static long instances;
long use_count() const
{
return use_count_;
}
#if !defined(BOOST_NO_ARGUMENT_DEPENDENT_LOOKUP)
inline friend void intrusive_ptr_add_ref(base * p)
{
++p->use_count_;
}
inline friend void intrusive_ptr_release(base * p)
{
if(--p->use_count_ == 0) delete p;
}
#else
void add_ref()
{
++use_count_;
}
void release()
{
if(--use_count_ == 0) delete this;
}
#endif
};
long base::instances = 0;
} // namespace N
#if defined(BOOST_NO_ARGUMENT_DEPENDENT_LOOKUP)
namespace boost
{
inline void intrusive_ptr_add_ref(N::base * p)
{
p->add_ref();
}
inline void intrusive_ptr_release(N::base * p)
{
p->release();
}
} // namespace boost
#endif
//
struct X: public virtual N::base
{
};
struct Y: public X
{
};
int main()
{
BOOST_TEST( N::base::instances == 0 );
{
boost::intrusive_ptr<X> p( new X );
BOOST_TEST( N::base::instances == 1 );
boost::intrusive_ptr<X> p2( std::move( p ) );
BOOST_TEST( N::base::instances == 1 );
BOOST_TEST( p.get() == 0 );
p2.reset();
BOOST_TEST( N::base::instances == 0 );
}
{
boost::intrusive_ptr<X> p( new X );
BOOST_TEST( N::base::instances == 1 );
boost::intrusive_ptr<X> p2;
p2 = std::move( p );
BOOST_TEST( N::base::instances == 1 );
BOOST_TEST( p.get() == 0 );
p2.reset();
BOOST_TEST( N::base::instances == 0 );
}
{
boost::intrusive_ptr<X> p( new X );
BOOST_TEST( N::base::instances == 1 );
boost::intrusive_ptr<X> p2( new X );
BOOST_TEST( N::base::instances == 2 );
p2 = std::move( p );
BOOST_TEST( N::base::instances == 1 );
BOOST_TEST( p.get() == 0 );
p2.reset();
BOOST_TEST( N::base::instances == 0 );
}
return boost::report_errors();
}
#else // !defined( BOOST_HAS_RVALUE_REFS )
int main()
{
return 0;
}
#endif

View File

@@ -1,19 +0,0 @@
//
// make_shared_fp_test.cpp
//
// Copyright 2010 Georg Fritzsche
//
// 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/shared_ptr.hpp>
#include <boost/make_shared.hpp>
int main()
{
typedef boost::shared_ptr<int>(*FP)();
FP fp = boost::make_shared<int>;
}

View File

@@ -1,98 +0,0 @@
// make_shared_perfect_forwarding_test.cpp - a test of make_shared
// perfect forwarding of constructor arguments when using a C++0x
// compiler.
//
// Copyright 2009 Frank Mori Hess
//
// 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>
#if !defined( BOOST_HAS_RVALUE_REFS ) || !defined( BOOST_HAS_VARIADIC_TMPL )
int main()
{
return 0;
}
#else // BOOST_HAS_RVALUE_REFS, BOOST_HAS_VARIADIC_TMPL
class myarg
{
public:
myarg()
{}
private:
myarg(myarg && other)
{}
myarg& operator=(myarg && other)
{
return *this;
}
myarg(const myarg & other)
{}
myarg& operator=(const myarg & other)
{
return *this;
}
};
class X
{
public:
enum constructor_id
{
move_constructor,
const_ref_constructor,
ref_constructor
};
X(myarg &&arg): constructed_by_(move_constructor)
{}
X(const myarg &arg): constructed_by_(const_ref_constructor)
{}
X(myarg &arg): constructed_by_(ref_constructor)
{}
constructor_id constructed_by_;
};
struct Y
{
Y(int &value): ref(value)
{}
int &ref;
};
int main()
{
{
myarg a;
boost::shared_ptr< X > x = boost::make_shared< X >(a);
BOOST_TEST( x->constructed_by_ == X::ref_constructor);
}
{
const myarg ca;
boost::shared_ptr< X > x = boost::make_shared< X >(ca);
BOOST_TEST( x->constructed_by_ == X::const_ref_constructor);
}
{
boost::shared_ptr< X > x = boost::make_shared< X >(myarg());
BOOST_TEST( x->constructed_by_ == X::move_constructor);
}
{
int value = 1;
boost::shared_ptr< Y > y = boost::make_shared< Y >(value);
BOOST_TEST( y->ref == 1 && value == y->ref );
++y->ref;
BOOST_TEST( value == y->ref );
}
return boost::report_errors();
}
#endif // BOOST_HAS_RVALUE_REFS

View File

@@ -9,8 +9,6 @@
// http://www.boost.org/LICENSE_1_0.txt)
//
#include <boost/config.hpp>
#include <boost/pointer_cast.hpp>
#include <boost/shared_ptr.hpp>
@@ -60,8 +58,6 @@ class derived_derived
// And now some simple check functions
#if !defined( BOOST_NO_RTTI )
template <class BasePtr>
bool check_dynamic_pointer_cast(const BasePtr &ptr)
{
@@ -78,8 +74,6 @@ bool check_dynamic_pointer_cast(const BasePtr &ptr)
dynamic_cast<derived_derived*>(boost::get_pointer(ptr));
}
#endif
template <class BasePtr>
bool check_static_pointer_cast(const BasePtr &ptr)
{
@@ -113,9 +107,7 @@ int main()
boost::shared_ptr<base> ptr(new derived);
#if !defined( BOOST_NO_RTTI )
BOOST_TEST( check_dynamic_pointer_cast( ptr ) );
#endif
BOOST_TEST( check_static_pointer_cast( ptr ) );
BOOST_TEST( check_const_pointer_cast( ptr ) );
}
@@ -125,9 +117,7 @@ int main()
boost::scoped_ptr<base> ptr(new derived);
#if !defined( BOOST_NO_RTTI )
BOOST_TEST( check_dynamic_pointer_cast( ptr.get() ) );
#endif
BOOST_TEST( check_static_pointer_cast( ptr.get() ) );
BOOST_TEST( check_const_pointer_cast( ptr.get() ) );
}

View File

@@ -63,12 +63,10 @@ void test()
px->f();
#if !defined( BOOST_NO_RTTI )
boost::shared_ptr<Y> py2 = boost::dynamic_pointer_cast<Y>(px);
BOOST_TEST(py.get() == py2.get());
BOOST_TEST(!(py < py2 || py2 < py));
BOOST_TEST(py.use_count() == 3);
#endif
}
catch( boost::bad_weak_ptr const& )
{

View File

@@ -188,7 +188,6 @@ int main()
test_eq(p, q);
}
#if !defined( BOOST_NO_RTTI )
shared_ptr<Y> p3 = dynamic_pointer_cast<Y>(p);
shared_ptr<Y> p4 = dynamic_pointer_cast<Y>(p2);
@@ -202,7 +201,6 @@ int main()
test_is_Y(p3);
test_eq2(p, p3);
test_ne2(p2, p4);
#endif
shared_ptr<void> p5(p);
@@ -216,17 +214,13 @@ int main()
p.reset();
p2.reset();
#if !defined( BOOST_NO_RTTI )
p3.reset();
p4.reset();
#endif
test_is_zero(p);
test_is_zero(p2);
#if !defined( BOOST_NO_RTTI )
test_is_zero(p3);
test_is_zero(p4);
#endif
BOOST_TEST(p5.use_count() == 1);
@@ -256,7 +250,6 @@ int main()
test_is_nonzero(wp2.lock());
}
#if !defined( BOOST_NO_RTTI )
weak_ptr<Y> wp3 = dynamic_pointer_cast<Y>(wp2.lock());
BOOST_TEST(wp3.use_count() == 1);
@@ -266,15 +259,12 @@ int main()
BOOST_TEST(wp4.use_count() == 1);
test_shared(wp2, wp4);
#endif
wp1 = p2;
test_is_zero(wp1.lock());
#if !defined( BOOST_NO_RTTI )
wp1 = p4;
wp1 = wp3;
#endif
wp1 = wp2;
BOOST_TEST(wp1.use_count() == 1);
@@ -289,9 +279,7 @@ int main()
BOOST_TEST(wp1.use_count() == 0);
BOOST_TEST(wp2.use_count() == 0);
#if !defined( BOOST_NO_RTTI )
BOOST_TEST(wp3.use_count() == 0);
#endif
// Test operator< stability for std::set< weak_ptr<> >
// Thanks to Joe Gottman for pointing this out

View File

@@ -8,11 +8,11 @@
// http://www.boost.org/LICENSE_1_0.txt
//
#if defined( BOOST_HAS_RVALUE_REFS )
#include <boost/shared_ptr.hpp>
#include <boost/detail/lightweight_test.hpp>
#if defined( BOOST_HAS_RVALUE_REFS )
struct X
{
static long instances;
@@ -43,11 +43,11 @@ int main()
boost::shared_ptr<X> p( new X );
BOOST_TEST( X::instances == 1 );
boost::shared_ptr<X> p2( std::move( p ) );
boost::shared_ptr<X> p2( static_cast< boost::shared_ptr<X> && >( p ) );
BOOST_TEST( X::instances == 1 );
BOOST_TEST( p.get() == 0 );
boost::shared_ptr<void> p3( std::move( p2 ) );
boost::shared_ptr<void> p3( static_cast< boost::shared_ptr<X> && >( p2 ) );
BOOST_TEST( X::instances == 1 );
BOOST_TEST( p2.get() == 0 );
@@ -60,12 +60,12 @@ int main()
BOOST_TEST( X::instances == 1 );
boost::shared_ptr<X> p2;
p2 = std::move( p );
p2 = static_cast< boost::shared_ptr<X> && >( p );
BOOST_TEST( X::instances == 1 );
BOOST_TEST( p.get() == 0 );
boost::shared_ptr<void> p3;
p3 = std::move( p2 );
p3 = static_cast< boost::shared_ptr<X> && >( p2 );
BOOST_TEST( X::instances == 1 );
BOOST_TEST( p2.get() == 0 );
@@ -79,13 +79,13 @@ int main()
boost::shared_ptr<X> p2( new X );
BOOST_TEST( X::instances == 2 );
p2 = std::move( p );
p2 = static_cast< boost::shared_ptr<X> && >( p );
BOOST_TEST( X::instances == 1 );
BOOST_TEST( p.get() == 0 );
boost::shared_ptr<void> p3( new X );
BOOST_TEST( X::instances == 2 );
p3 = std::move( p2 );
p3 = static_cast< boost::shared_ptr<X> && >( p2 );
BOOST_TEST( X::instances == 1 );
BOOST_TEST( p2.get() == 0 );

View File

@@ -2462,8 +2462,6 @@ void test()
} // namespace n_const_cast
#if !defined( BOOST_NO_RTTI )
namespace n_dynamic_cast
{
@@ -2529,8 +2527,6 @@ void test()
} // namespace n_dynamic_cast
#endif
namespace n_map
{
@@ -3204,12 +3200,10 @@ void test()
BOOST_TEST(px.get() != 0);
BOOST_TEST(py.use_count() == 2);
#if !defined( BOOST_NO_RTTI )
boost::shared_ptr<Y> py2 = boost::dynamic_pointer_cast<Y>(px);
BOOST_TEST(py.get() == py2.get());
BOOST_TEST(!(py < py2 || py2 < py));
BOOST_TEST(py.use_count() == 3);
#endif
}
} // namespace n_spt_shared_from_this
@@ -3235,9 +3229,7 @@ int main()
n_comparison::test();
n_static_cast::test();
n_const_cast::test();
#if !defined( BOOST_NO_RTTI )
n_dynamic_cast::test();
#endif
n_map::test();

View File

@@ -1,51 +0,0 @@
//
// sp_typeinfo_test.cpp
//
// Copyright (c) 2009 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/sp_typeinfo.hpp>
#include <boost/detail/lightweight_test.hpp>
#include <iostream>
int main()
{
BOOST_TEST( BOOST_SP_TYPEID( int ) == BOOST_SP_TYPEID( int ) );
BOOST_TEST( BOOST_SP_TYPEID( int ) != BOOST_SP_TYPEID( long ) );
BOOST_TEST( BOOST_SP_TYPEID( int ) != BOOST_SP_TYPEID( void ) );
boost::detail::sp_typeinfo const & ti = BOOST_SP_TYPEID( int );
boost::detail::sp_typeinfo const * pti = &BOOST_SP_TYPEID( int );
BOOST_TEST( *pti == ti );
BOOST_TEST( ti == ti );
BOOST_TEST( !( ti != ti ) );
BOOST_TEST( !ti.before( ti ) );
char const * nti = ti.name();
std::cout << nti << std::endl;
boost::detail::sp_typeinfo const & tv = BOOST_SP_TYPEID( void );
boost::detail::sp_typeinfo const * ptv = &BOOST_SP_TYPEID( void );
BOOST_TEST( *ptv == tv );
BOOST_TEST( tv == tv );
BOOST_TEST( !( tv != tv ) );
BOOST_TEST( !tv.before( tv ) );
char const * ntv = tv.name();
std::cout << ntv << std::endl;
BOOST_TEST( ti != tv );
BOOST_TEST( !( ti == tv ) );
BOOST_TEST( ti.before( tv ) != tv.before( ti ) );
return boost::report_errors();
}

View File

@@ -1,121 +0,0 @@
//
// weak_ptr_move_test.cpp
//
// Copyright (c) 2007 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/weak_ptr.hpp>
#include <boost/detail/lightweight_test.hpp>
#if defined( BOOST_HAS_RVALUE_REFS )
struct X
{
static long instances;
X()
{
++instances;
}
~X()
{
--instances;
}
private:
X( X const & );
X & operator=( X const & );
};
long X::instances = 0;
int main()
{
BOOST_TEST( X::instances == 0 );
{
boost::shared_ptr<X> p_( new X );
boost::weak_ptr<X> p( p_ );
BOOST_TEST( X::instances == 1 );
BOOST_TEST( p.use_count() == 1 );
boost::weak_ptr<X> p2( std::move( p ) );
BOOST_TEST( X::instances == 1 );
BOOST_TEST( p2.use_count() == 1 );
BOOST_TEST( p.expired() );
boost::weak_ptr<void> p3( std::move( p2 ) );
BOOST_TEST( X::instances == 1 );
BOOST_TEST( p3.use_count() == 1 );
BOOST_TEST( p2.expired() );
p_.reset();
BOOST_TEST( X::instances == 0 );
BOOST_TEST( p3.expired() );
}
{
boost::shared_ptr<X> p_( new X );
boost::weak_ptr<X> p( p_ );
BOOST_TEST( X::instances == 1 );
BOOST_TEST( p.use_count() == 1 );
boost::weak_ptr<X> p2;
p2 = static_cast< boost::weak_ptr<X> && >( p );
BOOST_TEST( X::instances == 1 );
BOOST_TEST( p2.use_count() == 1 );
BOOST_TEST( p.expired() );
boost::weak_ptr<void> p3;
p3 = std::move( p2 );
BOOST_TEST( X::instances == 1 );
BOOST_TEST( p3.use_count() == 1 );
BOOST_TEST( p2.expired() );
p_.reset();
BOOST_TEST( X::instances == 0 );
BOOST_TEST( p3.expired() );
}
{
boost::shared_ptr<X> p_( new X );
boost::weak_ptr<X> p( p_ );
BOOST_TEST( X::instances == 1 );
BOOST_TEST( p.use_count() == 1 );
boost::shared_ptr<X> p_2( new X );
boost::weak_ptr<X> p2( p_2 );
BOOST_TEST( X::instances == 2 );
p2 = std::move( p );
BOOST_TEST( X::instances == 2 );
BOOST_TEST( p2.use_count() == 1 );
BOOST_TEST( p.expired() );
BOOST_TEST( p2.lock() != p_2 );
boost::shared_ptr<void> p_3( new X );
boost::weak_ptr<void> p3( p_3 );
BOOST_TEST( X::instances == 3 );
p3 = std::move( p2 );
BOOST_TEST( X::instances == 3 );
BOOST_TEST( p3.use_count() == 1 );
BOOST_TEST( p2.expired() );
BOOST_TEST( p3.lock() != p_3 );
}
return boost::report_errors();
}
#else // !defined( BOOST_HAS_RVALUE_REFS )
int main()
{
return 0;
}
#endif

View File

@@ -914,6 +914,7 @@ void test()
BOOST_TEST(wp2.use_count() == 0);
BOOST_TEST(!(wp < wp3 || wp3 < wp));
using std::swap;
swap(wp, wp2);
BOOST_TEST(wp.use_count() == 0);
@@ -949,6 +950,7 @@ void test()
BOOST_TEST(wp2.use_count() == 0);
BOOST_TEST(!(wp < wp3 || wp3 < wp));
using std::swap;
swap(wp, wp2);
BOOST_TEST(wp.use_count() == 0);
@@ -963,6 +965,7 @@ void test()
BOOST_TEST(wp2.use_count() == 0);
BOOST_TEST(!(wp < wp3 || wp3 < wp));
using std::swap;
swap(wp, wp2);
BOOST_TEST(wp.use_count() == 0);