mirror of
https://github.com/boostorg/smart_ptr.git
synced 2025-10-04 19:51:02 +02:00
Compare commits
45 Commits
boost-1.39
...
boost-1.51
Author | SHA1 | Date | |
---|---|---|---|
|
6a56c95762 | ||
|
c2048732d8 | ||
|
5979c1d4bd | ||
|
3090f6f4af | ||
|
40073ef64f | ||
|
b9970eda45 | ||
|
9147489b4c | ||
|
d1348ea05e | ||
|
90db9a6435 | ||
|
1c208ad3ea | ||
|
5fc9bf5bc5 | ||
|
c846d230f0 | ||
|
7b097467d6 | ||
|
7cb040edb0 | ||
|
d6ac116b71 | ||
|
8abc8889d1 | ||
|
c5b47e2136 | ||
|
7c0815c567 | ||
|
210288f02e | ||
|
cf7b6904e8 | ||
|
b978919dd1 | ||
|
1086aff971 | ||
|
445e8d1728 | ||
|
545745d649 | ||
|
d71cc6ab08 | ||
|
0d77fd0678 | ||
|
6ca6d3ce6f | ||
|
cfc82854d3 | ||
|
b9d77d877e | ||
|
1f50e3abe4 | ||
|
697f338510 | ||
|
f4386409d9 | ||
|
ba349679f3 | ||
|
a3b84f8586 | ||
|
b0fd8a6b08 | ||
|
4f5062004a | ||
|
f040bed751 | ||
|
2f8945a885 | ||
|
2bd0778778 | ||
|
eec640bfd7 | ||
|
754fd941ee | ||
|
e94f64039d | ||
|
63b17c24ea | ||
|
8a421c2098 | ||
|
5fa1cbf6e1 |
@@ -1,30 +0,0 @@
|
||||
#----------------------------------------------------------------------------
|
||||
# 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
|
||||
)
|
||||
|
||||
|
@@ -29,20 +29,24 @@
|
||||
and <STRONG>shared_ptr<T const></STRONG>, depending on constness, to <STRONG>this</STRONG>.</P>
|
||||
<h3><a name="Example">Example</a></h3>
|
||||
<pre>
|
||||
class Y: public enable_shared_from_this<Y>
|
||||
#include <boost/enable_shared_from_this.hpp>
|
||||
#include <boost/shared_ptr.hpp>
|
||||
#include <cassert>
|
||||
|
||||
class Y: public boost::enable_shared_from_this<Y>
|
||||
{
|
||||
public:
|
||||
|
||||
shared_ptr<Y> f()
|
||||
boost::shared_ptr<Y> f()
|
||||
{
|
||||
return shared_from_this();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
int main()
|
||||
{
|
||||
shared_ptr<Y> p(new Y);
|
||||
shared_ptr<Y> q = p->f();
|
||||
boost::shared_ptr<Y> p(new Y);
|
||||
boost::shared_ptr<Y> q = p->f();
|
||||
assert(p == q);
|
||||
assert(!(p < q || q < p)); // p and q must share ownership
|
||||
}
|
||||
|
@@ -19,20 +19,72 @@
|
||||
|
||||
#if defined( BOOST_NO_TYPEID )
|
||||
|
||||
#include <boost/current_function.hpp>
|
||||
#include <functional>
|
||||
|
||||
namespace boost
|
||||
{
|
||||
|
||||
namespace detail
|
||||
{
|
||||
|
||||
typedef void* sp_typeinfo;
|
||||
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_;
|
||||
}
|
||||
};
|
||||
|
||||
template<class T> struct sp_typeid_
|
||||
{
|
||||
static char v_;
|
||||
static sp_typeinfo ti_;
|
||||
|
||||
static char const * name()
|
||||
{
|
||||
return BOOST_CURRENT_FUNCTION;
|
||||
}
|
||||
};
|
||||
|
||||
template<class T> char sp_typeid_< T >::v_;
|
||||
#if defined(__SUNPRO_CC)
|
||||
// see #4199, the Sun Studio compiler gets confused about static initialization
|
||||
// constructor arguments. But an assignment works just fine.
|
||||
template<class T> sp_typeinfo sp_typeid_< T >::ti_ = sp_typeid_< T >::name();
|
||||
#else
|
||||
template<class T> sp_typeinfo sp_typeid_< T >::ti_(sp_typeid_< T >::name());
|
||||
#endif
|
||||
|
||||
template<class T> struct sp_typeid_< T & >: sp_typeid_< T >
|
||||
{
|
||||
};
|
||||
|
||||
template<class T> struct sp_typeid_< T const >: sp_typeid_< T >
|
||||
{
|
||||
@@ -50,7 +102,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>::v_)
|
||||
#define BOOST_SP_TYPEID(T) (boost::detail::sp_typeid_<T>::ti_)
|
||||
|
||||
#else
|
||||
|
||||
|
@@ -11,7 +11,7 @@
|
||||
//
|
||||
// Defines enum boost::memory_order per the C++0x working draft
|
||||
//
|
||||
// Copyright (c) 2008 Peter Dimov
|
||||
// Copyright (c) 2008, 2009 Peter Dimov
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// See accompanying file LICENSE_1_0.txt or copy at
|
||||
@@ -21,13 +21,31 @@
|
||||
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_seq_cst = 7, // acq_rel | 4
|
||||
memory_order_consume = 8
|
||||
};
|
||||
|
||||
} // namespace boost
|
||||
|
@@ -1,3 +1,6 @@
|
||||
#ifndef BOOST_SMART_PTR_HPP_INCLUDED
|
||||
#define BOOST_SMART_PTR_HPP_INCLUDED
|
||||
|
||||
//
|
||||
// smart_ptr.hpp
|
||||
//
|
||||
@@ -22,4 +25,7 @@
|
||||
# include <boost/weak_ptr.hpp>
|
||||
# include <boost/intrusive_ptr.hpp>
|
||||
# include <boost/enable_shared_from_this.hpp>
|
||||
# include <boost/make_shared.hpp>
|
||||
#endif
|
||||
|
||||
#endif // #ifndef BOOST_SMART_PTR_HPP_INCLUDED
|
||||
|
@@ -17,6 +17,7 @@
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
|
||||
#include <boost/assert.hpp>
|
||||
#include <pthread.h>
|
||||
|
||||
namespace boost
|
||||
@@ -42,15 +43,15 @@ public:
|
||||
// HPUX 10.20 / DCE has a nonstandard pthread_mutex_init
|
||||
|
||||
#if defined(__hpux) && defined(_DECTHREADS_)
|
||||
pthread_mutex_init(&m_, pthread_mutexattr_default);
|
||||
BOOST_VERIFY( pthread_mutex_init( &m_, pthread_mutexattr_default ) == 0 );
|
||||
#else
|
||||
pthread_mutex_init(&m_, 0);
|
||||
BOOST_VERIFY( pthread_mutex_init( &m_, 0 ) == 0 );
|
||||
#endif
|
||||
}
|
||||
|
||||
~lightweight_mutex()
|
||||
{
|
||||
pthread_mutex_destroy(&m_);
|
||||
BOOST_VERIFY( pthread_mutex_destroy( &m_ ) == 0 );
|
||||
}
|
||||
|
||||
class scoped_lock;
|
||||
@@ -69,12 +70,12 @@ public:
|
||||
|
||||
scoped_lock(lightweight_mutex & m): m_(m.m_)
|
||||
{
|
||||
pthread_mutex_lock(&m_);
|
||||
BOOST_VERIFY( pthread_mutex_lock( &m_ ) == 0 );
|
||||
}
|
||||
|
||||
~scoped_lock()
|
||||
{
|
||||
pthread_mutex_unlock(&m_);
|
||||
BOOST_VERIFY( pthread_mutex_unlock( &m_ ) == 0 );
|
||||
}
|
||||
};
|
||||
};
|
||||
|
@@ -74,8 +74,9 @@ template<unsigned size, unsigned align_> struct allocator_impl
|
||||
|
||||
static lightweight_mutex & mutex()
|
||||
{
|
||||
static lightweight_mutex m;
|
||||
return m;
|
||||
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 * mutex_init;
|
||||
|
@@ -52,6 +52,10 @@ int const weak_count_id = 0x298C38A4;
|
||||
|
||||
struct sp_nothrow_tag {};
|
||||
|
||||
template< class D > struct sp_inplace_tag
|
||||
{
|
||||
};
|
||||
|
||||
class weak_count;
|
||||
|
||||
class shared_count
|
||||
@@ -142,6 +146,40 @@ public:
|
||||
#endif
|
||||
}
|
||||
|
||||
#if !defined( BOOST_NO_FUNCTION_TEMPLATE_ORDERING )
|
||||
|
||||
template< class P, class D > shared_count( P p, sp_inplace_tag<D> ): pi_( 0 )
|
||||
#if defined(BOOST_SP_ENABLE_DEBUG_HOOKS)
|
||||
, id_(shared_count_id)
|
||||
#endif
|
||||
{
|
||||
#ifndef BOOST_NO_EXCEPTIONS
|
||||
|
||||
try
|
||||
{
|
||||
pi_ = new sp_counted_impl_pd< P, D >( p );
|
||||
}
|
||||
catch( ... )
|
||||
{
|
||||
D()( p ); // delete p
|
||||
throw;
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
pi_ = new sp_counted_impl_pd< P, D >( p );
|
||||
|
||||
if( pi_ == 0 )
|
||||
{
|
||||
D()( p ); // delete p
|
||||
boost::throw_exception( std::bad_alloc() );
|
||||
}
|
||||
|
||||
#endif // #ifndef BOOST_NO_EXCEPTIONS
|
||||
}
|
||||
|
||||
#endif // !defined( BOOST_NO_FUNCTION_TEMPLATE_ORDERING )
|
||||
|
||||
template<class P, class D, class A> shared_count( P p, D d, A a ): pi_( 0 )
|
||||
#if defined(BOOST_SP_ENABLE_DEBUG_HOOKS)
|
||||
, id_(shared_count_id)
|
||||
@@ -188,6 +226,56 @@ public:
|
||||
#endif
|
||||
}
|
||||
|
||||
#if !defined( BOOST_NO_FUNCTION_TEMPLATE_ORDERING )
|
||||
|
||||
template< class P, class D, class A > shared_count( P p, sp_inplace_tag< D >, A a ): pi_( 0 )
|
||||
#if defined(BOOST_SP_ENABLE_DEBUG_HOOKS)
|
||||
, id_(shared_count_id)
|
||||
#endif
|
||||
{
|
||||
typedef sp_counted_impl_pda< P, D, A > impl_type;
|
||||
typedef typename A::template rebind< impl_type >::other A2;
|
||||
|
||||
A2 a2( a );
|
||||
|
||||
#ifndef BOOST_NO_EXCEPTIONS
|
||||
|
||||
try
|
||||
{
|
||||
pi_ = a2.allocate( 1, static_cast< impl_type* >( 0 ) );
|
||||
new( static_cast< void* >( pi_ ) ) impl_type( p, a );
|
||||
}
|
||||
catch(...)
|
||||
{
|
||||
D()( p );
|
||||
|
||||
if( pi_ != 0 )
|
||||
{
|
||||
a2.deallocate( static_cast< impl_type* >( pi_ ), 1 );
|
||||
}
|
||||
|
||||
throw;
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
pi_ = a2.allocate( 1, static_cast< impl_type* >( 0 ) );
|
||||
|
||||
if( pi_ != 0 )
|
||||
{
|
||||
new( static_cast< void* >( pi_ ) ) impl_type( p, a );
|
||||
}
|
||||
else
|
||||
{
|
||||
D()( p );
|
||||
boost::throw_exception( std::bad_alloc() );
|
||||
}
|
||||
|
||||
#endif // #ifndef BOOST_NO_EXCEPTIONS
|
||||
}
|
||||
|
||||
#endif // !defined( BOOST_NO_FUNCTION_TEMPLATE_ORDERING )
|
||||
|
||||
#ifndef BOOST_NO_AUTO_PTR
|
||||
|
||||
// auto_ptr<Y> is special cased to provide the strong guarantee
|
||||
@@ -333,6 +421,20 @@ 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();
|
||||
|
@@ -25,7 +25,7 @@
|
||||
# define BOOST_SP_NO_SP_CONVERTIBLE
|
||||
#endif
|
||||
|
||||
#if !defined( BOOST_SP_NO_SP_CONVERTIBLE ) && defined( __BORLANDC__ ) && ( __BORLANDC__ <= 0x610 )
|
||||
#if !defined( BOOST_SP_NO_SP_CONVERTIBLE ) && defined( __BORLANDC__ ) && ( __BORLANDC__ < 0x630 )
|
||||
# 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( (Y*)0 ) ) == sizeof(yes) };
|
||||
enum _vt { value = sizeof( (f)( static_cast<Y*>(0) ) ) == sizeof(yes) };
|
||||
};
|
||||
|
||||
struct sp_empty
|
||||
|
@@ -41,6 +41,9 @@
|
||||
#elif defined(__HP_aCC) && defined(__ia64)
|
||||
# include <boost/smart_ptr/detail/sp_counted_base_acc_ia64.hpp>
|
||||
|
||||
#elif defined( __IBMCPP__ ) && defined( __powerpc )
|
||||
# include <boost/smart_ptr/detail/sp_counted_base_vacpp_ppc.hpp>
|
||||
|
||||
#elif defined( __MWERKS__ ) && defined( __POWERPC__ )
|
||||
# include <boost/smart_ptr/detail/sp_counted_base_cw_ppc.hpp>
|
||||
|
||||
|
142
include/boost/smart_ptr/detail/sp_counted_base_aix.hpp
Normal file
142
include/boost/smart_ptr/detail/sp_counted_base_aix.hpp
Normal file
@@ -0,0 +1,142 @@
|
||||
#ifndef BOOST_SMART_PTR_DETAIL_SP_COUNTED_BASE_AIX_HPP_INCLUDED
|
||||
#define BOOST_SMART_PTR_DETAIL_SP_COUNTED_BASE_AIX_HPP_INCLUDED
|
||||
|
||||
//
|
||||
// detail/sp_counted_base_aix.hpp
|
||||
// based on: detail/sp_counted_base_w32.hpp
|
||||
//
|
||||
// Copyright (c) 2001, 2002, 2003 Peter Dimov and Multi Media Ltd.
|
||||
// Copyright 2004-2005 Peter Dimov
|
||||
// Copyright 2006 Michael van der Westhuizen
|
||||
//
|
||||
// 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)
|
||||
//
|
||||
//
|
||||
// Lock-free algorithm by Alexander Terekhov
|
||||
//
|
||||
// Thanks to Ben Hitchings for the #weak + (#shared != 0)
|
||||
// formulation
|
||||
//
|
||||
|
||||
#include <boost/detail/sp_typeinfo.hpp>
|
||||
#include <builtins.h>
|
||||
#include <sys/atomic_op.h>
|
||||
|
||||
namespace boost
|
||||
{
|
||||
|
||||
namespace detail
|
||||
{
|
||||
|
||||
inline void atomic_increment( int32_t* pw )
|
||||
{
|
||||
// ++*pw;
|
||||
|
||||
fetch_and_add( pw, 1 );
|
||||
}
|
||||
|
||||
inline int32_t atomic_decrement( int32_t * pw )
|
||||
{
|
||||
// return --*pw;
|
||||
|
||||
int32_t originalValue;
|
||||
|
||||
__lwsync();
|
||||
originalValue = fetch_and_add( pw, -1 );
|
||||
__isync();
|
||||
|
||||
return (originalValue - 1);
|
||||
}
|
||||
|
||||
inline int32_t atomic_conditional_increment( int32_t * pw )
|
||||
{
|
||||
// if( *pw != 0 ) ++*pw;
|
||||
// return *pw;
|
||||
|
||||
int32_t tmp = fetch_and_add( pw, 0 );
|
||||
for( ;; )
|
||||
{
|
||||
if( tmp == 0 ) return 0;
|
||||
if( compare_and_swap( pw, &tmp, tmp + 1 ) ) return (tmp + 1);
|
||||
}
|
||||
}
|
||||
|
||||
class sp_counted_base
|
||||
{
|
||||
private:
|
||||
|
||||
sp_counted_base( sp_counted_base const & );
|
||||
sp_counted_base & operator= ( sp_counted_base const & );
|
||||
|
||||
int32_t use_count_; // #shared
|
||||
int32_t weak_count_; // #weak + (#shared != 0)
|
||||
|
||||
public:
|
||||
|
||||
sp_counted_base(): use_count_( 1 ), weak_count_( 1 )
|
||||
{
|
||||
}
|
||||
|
||||
virtual ~sp_counted_base() // nothrow
|
||||
{
|
||||
}
|
||||
|
||||
// dispose() is called when use_count_ drops to zero, to release
|
||||
// the resources managed by *this.
|
||||
|
||||
virtual void dispose() = 0; // nothrow
|
||||
|
||||
// destroy() is called when weak_count_ drops to zero.
|
||||
|
||||
virtual void destroy() // nothrow
|
||||
{
|
||||
delete this;
|
||||
}
|
||||
|
||||
virtual void * get_deleter( sp_typeinfo const & ti ) = 0;
|
||||
|
||||
void add_ref_copy()
|
||||
{
|
||||
atomic_increment( &use_count_ );
|
||||
}
|
||||
|
||||
bool add_ref_lock() // true on success
|
||||
{
|
||||
return atomic_conditional_increment( &use_count_ ) != 0;
|
||||
}
|
||||
|
||||
void release() // nothrow
|
||||
{
|
||||
if( atomic_decrement( &use_count_ ) == 0 )
|
||||
{
|
||||
dispose();
|
||||
weak_release();
|
||||
}
|
||||
}
|
||||
|
||||
void weak_add_ref() // nothrow
|
||||
{
|
||||
atomic_increment( &weak_count_ );
|
||||
}
|
||||
|
||||
void weak_release() // nothrow
|
||||
{
|
||||
if( atomic_decrement( &weak_count_ ) == 0 )
|
||||
{
|
||||
destroy();
|
||||
}
|
||||
}
|
||||
|
||||
long use_count() const // nothrow
|
||||
{
|
||||
return fetch_and_add( const_cast<int32_t*>(&use_count_), 0 );
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace detail
|
||||
|
||||
} // namespace boost
|
||||
|
||||
#endif // #ifndef BOOST_SMART_PTR_DETAIL_SP_COUNTED_BASE_AIX_HPP_INCLUDED
|
@@ -37,9 +37,12 @@ inline void atomic_increment( int * pw )
|
||||
__asm__ __volatile__
|
||||
(
|
||||
"0:\n\t"
|
||||
".set push\n\t"
|
||||
".set mips2\n\t"
|
||||
"ll %0, %1\n\t"
|
||||
"addiu %0, 1\n\t"
|
||||
"sc %0, %1\n\t"
|
||||
".set pop\n\t"
|
||||
"beqz %0, 0b":
|
||||
"=&r"( tmp ), "=m"( *pw ):
|
||||
"m"( *pw )
|
||||
@@ -55,9 +58,12 @@ inline int atomic_decrement( int * pw )
|
||||
__asm__ __volatile__
|
||||
(
|
||||
"0:\n\t"
|
||||
".set push\n\t"
|
||||
".set mips2\n\t"
|
||||
"ll %1, %2\n\t"
|
||||
"addiu %0, %1, -1\n\t"
|
||||
"sc %0, %2\n\t"
|
||||
".set pop\n\t"
|
||||
"beqz %0, 0b\n\t"
|
||||
"addiu %0, %1, -1":
|
||||
"=&r"( rv ), "=&r"( tmp ), "=m"( *pw ):
|
||||
@@ -78,10 +84,13 @@ inline int atomic_conditional_increment( int * pw )
|
||||
__asm__ __volatile__
|
||||
(
|
||||
"0:\n\t"
|
||||
".set push\n\t"
|
||||
".set mips2\n\t"
|
||||
"ll %0, %2\n\t"
|
||||
"beqz %0, 1f\n\t"
|
||||
"addiu %1, %0, 1\n\t"
|
||||
"sc %1, %2\n\t"
|
||||
".set pop\n\t"
|
||||
"beqz %1, 0b\n\t"
|
||||
"addiu %0, %0, 1\n\t"
|
||||
"1:":
|
||||
|
@@ -30,9 +30,9 @@ namespace detail
|
||||
|
||||
inline int32_t compare_and_swap( int32_t * dest_, int32_t compare_, int32_t swap_ )
|
||||
{
|
||||
__asm__ __volatile__( "cas %0, %2, %1"
|
||||
: "+m" (*dest_), "+r" (swap_)
|
||||
: "r" (compare_)
|
||||
__asm__ __volatile__( "cas [%1], %2, %0"
|
||||
: "+r" (swap_)
|
||||
: "r" (dest_), "r" (compare_)
|
||||
: "memory" );
|
||||
|
||||
return swap_;
|
||||
|
150
include/boost/smart_ptr/detail/sp_counted_base_vacpp_ppc.hpp
Normal file
150
include/boost/smart_ptr/detail/sp_counted_base_vacpp_ppc.hpp
Normal file
@@ -0,0 +1,150 @@
|
||||
#ifndef BOOST_SMART_PTR_DETAIL_SP_COUNTED_BASE_VACPP_PPC_HPP_INCLUDED
|
||||
#define BOOST_SMART_PTR_DETAIL_SP_COUNTED_BASE_VACPP_PPC_HPP_INCLUDED
|
||||
|
||||
//
|
||||
// detail/sp_counted_base_vacpp_ppc.hpp - xlC(vacpp) on POWER
|
||||
// based on: detail/sp_counted_base_w32.hpp
|
||||
//
|
||||
// Copyright (c) 2001, 2002, 2003 Peter Dimov and Multi Media Ltd.
|
||||
// Copyright 2004-2005 Peter Dimov
|
||||
// Copyright 2006 Michael van der Westhuizen
|
||||
// Copyright 2012 IBM Corp.
|
||||
//
|
||||
// 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)
|
||||
//
|
||||
//
|
||||
// Lock-free algorithm by Alexander Terekhov
|
||||
//
|
||||
// Thanks to Ben Hitchings for the #weak + (#shared != 0)
|
||||
// formulation
|
||||
//
|
||||
|
||||
#include <boost/detail/sp_typeinfo.hpp>
|
||||
|
||||
extern "builtin" void __lwsync(void);
|
||||
extern "builtin" void __isync(void);
|
||||
extern "builtin" int __fetch_and_add(volatile int* addr, int val);
|
||||
extern "builtin" int __compare_and_swap(volatile int*, int*, int);
|
||||
|
||||
namespace boost
|
||||
{
|
||||
|
||||
namespace detail
|
||||
{
|
||||
|
||||
inline void atomic_increment( int *pw )
|
||||
{
|
||||
// ++*pw;
|
||||
__lwsync();
|
||||
__fetch_and_add(pw, 1);
|
||||
__isync();
|
||||
}
|
||||
|
||||
inline int atomic_decrement( int *pw )
|
||||
{
|
||||
// return --*pw;
|
||||
__lwsync();
|
||||
int originalValue = __fetch_and_add(pw, -1);
|
||||
__isync();
|
||||
|
||||
return (originalValue - 1);
|
||||
}
|
||||
|
||||
inline int atomic_conditional_increment( int *pw )
|
||||
{
|
||||
// if( *pw != 0 ) ++*pw;
|
||||
// return *pw;
|
||||
|
||||
__lwsync();
|
||||
int v = *const_cast<volatile int*>(pw);
|
||||
for (;;)
|
||||
// loop until state is known
|
||||
{
|
||||
if (v == 0) return 0;
|
||||
if (__compare_and_swap(pw, &v, v + 1))
|
||||
{
|
||||
__isync(); return (v + 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class sp_counted_base
|
||||
{
|
||||
private:
|
||||
|
||||
sp_counted_base( sp_counted_base const & );
|
||||
sp_counted_base & operator= ( sp_counted_base const & );
|
||||
|
||||
int use_count_; // #shared
|
||||
int weak_count_; // #weak + (#shared != 0)
|
||||
char pad[64] __attribute__((__aligned__(64)));
|
||||
// pad to prevent false sharing
|
||||
public:
|
||||
|
||||
sp_counted_base(): use_count_( 1 ), weak_count_( 1 )
|
||||
{
|
||||
}
|
||||
|
||||
virtual ~sp_counted_base() // nothrow
|
||||
{
|
||||
}
|
||||
|
||||
// dispose() is called when use_count_ drops to zero, to release
|
||||
// the resources managed by *this.
|
||||
|
||||
virtual void dispose() = 0; // nothrow
|
||||
|
||||
// destroy() is called when weak_count_ drops to zero.
|
||||
|
||||
virtual void destroy() // nothrow
|
||||
{
|
||||
delete this;
|
||||
}
|
||||
|
||||
virtual void * get_deleter( sp_typeinfo const & ti ) = 0;
|
||||
|
||||
void add_ref_copy()
|
||||
{
|
||||
atomic_increment( &use_count_ );
|
||||
}
|
||||
|
||||
bool add_ref_lock() // true on success
|
||||
{
|
||||
return atomic_conditional_increment( &use_count_ ) != 0;
|
||||
}
|
||||
|
||||
void release() // nothrow
|
||||
{
|
||||
if( atomic_decrement( &use_count_ ) == 0 )
|
||||
{
|
||||
dispose();
|
||||
weak_release();
|
||||
}
|
||||
}
|
||||
|
||||
void weak_add_ref() // nothrow
|
||||
{
|
||||
atomic_increment( &weak_count_ );
|
||||
}
|
||||
|
||||
void weak_release() // nothrow
|
||||
{
|
||||
if( atomic_decrement( &weak_count_ ) == 0 )
|
||||
{
|
||||
destroy();
|
||||
}
|
||||
}
|
||||
|
||||
long use_count() const // nothrow
|
||||
{
|
||||
return *const_cast<volatile int*>(&use_count_);
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace detail
|
||||
|
||||
} // namespace boost
|
||||
|
||||
#endif // #ifndef BOOST_SMART_PTR_DETAIL_SP_COUNTED_BASE_VACPP_PPC_HPP_INCLUDED
|
@@ -135,7 +135,11 @@ public:
|
||||
|
||||
// pre: d(p) must not throw
|
||||
|
||||
sp_counted_impl_pd( P p, D d ): ptr(p), del(d)
|
||||
sp_counted_impl_pd( P p, D & d ): ptr( p ), del( d )
|
||||
{
|
||||
}
|
||||
|
||||
sp_counted_impl_pd( P p ): ptr( p ), del()
|
||||
{
|
||||
}
|
||||
|
||||
@@ -195,7 +199,11 @@ public:
|
||||
|
||||
// pre: d( p ) must not throw
|
||||
|
||||
sp_counted_impl_pda( P p, D d, A a ): p_( p ), d_( d ), a_( a )
|
||||
sp_counted_impl_pda( P p, D & d, A a ): p_( p ), d_( d ), a_( a )
|
||||
{
|
||||
}
|
||||
|
||||
sp_counted_impl_pda( P p, A a ): p_( p ), d_(), a_( a )
|
||||
{
|
||||
}
|
||||
|
||||
|
@@ -20,7 +20,7 @@
|
||||
// are available.
|
||||
//
|
||||
|
||||
#if defined(__GNUC__) && ( __GNUC__ * 100 + __GNUC_MINOR__ >= 401 )
|
||||
#if defined( __GNUC__ ) && ( __GNUC__ * 100 + __GNUC_MINOR__ >= 401 ) && !defined( BOOST_SP_NO_SYNC )
|
||||
|
||||
#define BOOST_SP_HAS_SYNC
|
||||
|
||||
@@ -36,11 +36,15 @@
|
||||
#undef BOOST_SP_HAS_SYNC
|
||||
#endif
|
||||
|
||||
#if defined( __sh__ )
|
||||
#undef BOOST_SP_HAS_SYNC
|
||||
#endif
|
||||
|
||||
#if defined( __sparc__ )
|
||||
#undef BOOST_SP_HAS_SYNC
|
||||
#endif
|
||||
|
||||
#if defined( __INTEL_COMPILER ) && !defined( __ia64__ )
|
||||
#if defined( __INTEL_COMPILER ) && !defined( __ia64__ ) && ( __INTEL_COMPILER < 1100 )
|
||||
#undef BOOST_SP_HAS_SYNC
|
||||
#endif
|
||||
|
||||
|
@@ -31,7 +31,10 @@
|
||||
#include <boost/config.hpp>
|
||||
#include <boost/smart_ptr/detail/sp_has_sync.hpp>
|
||||
|
||||
#if defined(__GNUC__) && defined( __arm__ ) && !defined( __thumb__ )
|
||||
#if defined( BOOST_SP_USE_PTHREADS )
|
||||
# include <boost/smart_ptr/detail/spinlock_pt.hpp>
|
||||
|
||||
#elif defined(__GNUC__) && defined( __arm__ ) && !defined( __thumb__ )
|
||||
# include <boost/smart_ptr/detail/spinlock_gcc_arm.hpp>
|
||||
|
||||
#elif defined( BOOST_SP_HAS_SYNC )
|
||||
|
@@ -2,7 +2,7 @@
|
||||
#define BOOST_SMART_PTR_DETAIL_SPINLOCK_GCC_ARM_HPP_INCLUDED
|
||||
|
||||
//
|
||||
// Copyright (c) 2008 Peter Dimov
|
||||
// Copyright (c) 2008, 2011 Peter Dimov
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// See accompanying file LICENSE_1_0.txt or copy at
|
||||
@@ -11,6 +11,20 @@
|
||||
|
||||
#include <boost/smart_ptr/detail/yield_k.hpp>
|
||||
|
||||
#if defined(__ARM_ARCH_7__) || defined(__ARM_ARCH_7A__) || defined(__ARM_ARCH_7R__) || defined(__ARM_ARCH_7M__) || defined(__ARM_ARCH_7EM__)
|
||||
|
||||
# define BOOST_SP_ARM_BARRIER "dmb"
|
||||
|
||||
#elif defined(__ARM_ARCH_6__) || defined(__ARM_ARCH_6J__) || defined(__ARM_ARCH_6K__) || defined(__ARM_ARCH_6Z__) || defined(__ARM_ARCH_6ZK__) || defined(__ARM_ARCH_6T2__)
|
||||
|
||||
# define BOOST_SP_ARM_BARRIER "mcr p15, 0, r0, c7, c10, 5"
|
||||
|
||||
#else
|
||||
|
||||
# define BOOST_SP_ARM_BARRIER ""
|
||||
|
||||
#endif
|
||||
|
||||
namespace boost
|
||||
{
|
||||
|
||||
@@ -29,12 +43,38 @@ public:
|
||||
{
|
||||
int r;
|
||||
|
||||
#if defined(__ARM_ARCH_6__) \
|
||||
|| defined(__ARM_ARCH_6J__) \
|
||||
|| defined(__ARM_ARCH_6K__) \
|
||||
|| defined(__ARM_ARCH_6Z__) \
|
||||
|| defined(__ARM_ARCH_6ZK__) \
|
||||
|| defined(__ARM_ARCH_6T2__) \
|
||||
|| defined(__ARM_ARCH_7__) \
|
||||
|| defined(__ARM_ARCH_7A__) \
|
||||
|| defined(__ARM_ARCH_7R__) \
|
||||
|| defined(__ARM_ARCH_7M__) \
|
||||
|| defined(__ARM_ARCH_7EM__)
|
||||
|
||||
__asm__ __volatile__(
|
||||
"swp %0, %1, [%2]":
|
||||
"ldrex %0, [%2]; \n"
|
||||
"cmp %0, %1; \n"
|
||||
"strexne %0, %1, [%2]; \n"
|
||||
BOOST_SP_ARM_BARRIER :
|
||||
"=&r"( r ): // outputs
|
||||
"r"( 1 ), "r"( &v_ ): // inputs
|
||||
"memory", "cc" );
|
||||
|
||||
#else
|
||||
|
||||
__asm__ __volatile__(
|
||||
"swp %0, %1, [%2];\n"
|
||||
BOOST_SP_ARM_BARRIER :
|
||||
"=&r"( r ): // outputs
|
||||
"r"( 1 ), "r"( &v_ ): // inputs
|
||||
"memory", "cc" );
|
||||
|
||||
#endif
|
||||
|
||||
return r == 0;
|
||||
}
|
||||
|
||||
@@ -48,7 +88,7 @@ public:
|
||||
|
||||
void unlock()
|
||||
{
|
||||
__asm__ __volatile__( "" ::: "memory" );
|
||||
__asm__ __volatile__( BOOST_SP_ARM_BARRIER ::: "memory" );
|
||||
*const_cast< int volatile* >( &v_ ) = 0;
|
||||
}
|
||||
|
||||
@@ -82,4 +122,6 @@ public:
|
||||
|
||||
#define BOOST_DETAIL_SPINLOCK_INIT {0}
|
||||
|
||||
#undef BOOST_SP_ARM_BARRIER
|
||||
|
||||
#endif // #ifndef BOOST_SMART_PTR_DETAIL_SPINLOCK_GCC_ARM_HPP_INCLUDED
|
||||
|
@@ -41,7 +41,11 @@ public:
|
||||
|
||||
static spinlock & spinlock_for( void const * pv )
|
||||
{
|
||||
#if defined(__VMS) && __INITIAL_POINTER_SIZE == 64
|
||||
std::size_t i = reinterpret_cast< unsigned long long >( pv ) % 41;
|
||||
#else
|
||||
std::size_t i = reinterpret_cast< std::size_t >( pv ) % 41;
|
||||
#endif
|
||||
return pool_[ i ];
|
||||
}
|
||||
|
||||
|
@@ -55,7 +55,7 @@ namespace detail
|
||||
{
|
||||
|
||||
#if !defined( BOOST_USE_WINDOWS_H )
|
||||
extern "C" void __stdcall Sleep( unsigned ms );
|
||||
extern "C" void __stdcall Sleep( unsigned long ms );
|
||||
#endif
|
||||
|
||||
inline void yield( unsigned k )
|
||||
|
132
include/boost/smart_ptr/enable_shared_from_this2.hpp
Normal file
132
include/boost/smart_ptr/enable_shared_from_this2.hpp
Normal file
@@ -0,0 +1,132 @@
|
||||
#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
|
@@ -15,11 +15,6 @@
|
||||
|
||||
#include <boost/config.hpp>
|
||||
|
||||
#ifdef BOOST_MSVC // moved here to work around VC++ compiler crash
|
||||
# pragma warning(push)
|
||||
# pragma warning(disable:4284) // odd return type for operator->
|
||||
#endif
|
||||
|
||||
#include <boost/assert.hpp>
|
||||
#include <boost/detail/workaround.hpp>
|
||||
#include <boost/smart_ptr/detail/sp_convertible.hpp>
|
||||
@@ -77,7 +72,7 @@ public:
|
||||
template<class U>
|
||||
#if !defined( BOOST_SP_NO_SP_CONVERTIBLE )
|
||||
|
||||
intrusive_ptr( intrusive_ptr<U> const & rhs, typename detail::sp_enable_if_convertible<U,T>::type = detail::sp_empty() )
|
||||
intrusive_ptr( intrusive_ptr<U> const & rhs, typename boost::detail::sp_enable_if_convertible<U,T>::type = boost::detail::sp_empty() )
|
||||
|
||||
#else
|
||||
|
||||
@@ -109,6 +104,23 @@ 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)
|
||||
@@ -273,10 +285,15 @@ template<class E, class T, class Y> std::basic_ostream<E, T> & operator<< (std::
|
||||
|
||||
#endif // !defined(BOOST_NO_IOSTREAM)
|
||||
|
||||
// hash_value
|
||||
|
||||
template< class T > struct hash;
|
||||
|
||||
template< class T > std::size_t hash_value( boost::intrusive_ptr<T> const & p )
|
||||
{
|
||||
return boost::hash< T* >()( p.get() );
|
||||
}
|
||||
|
||||
} // namespace boost
|
||||
|
||||
#ifdef BOOST_MSVC
|
||||
# pragma warning(pop)
|
||||
#endif
|
||||
|
||||
#endif // #ifndef BOOST_SMART_PTR_INTRUSIVE_PTR_HPP_INCLUDED
|
||||
|
@@ -49,7 +49,18 @@ private:
|
||||
{
|
||||
if( initialized_ )
|
||||
{
|
||||
#if defined( __GNUC__ )
|
||||
|
||||
// fixes incorrect aliasing warning
|
||||
T * p = reinterpret_cast< T* >( storage_.data_ );
|
||||
p->~T();
|
||||
|
||||
#else
|
||||
|
||||
reinterpret_cast< T* >( storage_.data_ )->~T();
|
||||
|
||||
#endif
|
||||
|
||||
initialized_ = false;
|
||||
}
|
||||
}
|
||||
@@ -86,22 +97,32 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
template< class T > T forward( T t )
|
||||
#if defined( BOOST_HAS_RVALUE_REFS )
|
||||
|
||||
template< class T > T&& sp_forward( T & t )
|
||||
{
|
||||
return t;
|
||||
return static_cast< T&& >( t );
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
} // namespace detail
|
||||
|
||||
#if !defined( BOOST_NO_FUNCTION_TEMPLATE_ORDERING )
|
||||
# define BOOST_SP_MSD( T ) boost::detail::sp_inplace_tag< boost::detail::sp_ms_deleter< T > >()
|
||||
#else
|
||||
# define BOOST_SP_MSD( T ) boost::detail::sp_ms_deleter< T >()
|
||||
#endif
|
||||
|
||||
// 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 >() );
|
||||
boost::shared_ptr< T > pt( static_cast< T* >( 0 ), BOOST_SP_MSD( T ) );
|
||||
|
||||
detail::sp_ms_deleter< T > * pd = boost::get_deleter< detail::sp_ms_deleter< T > >( pt );
|
||||
boost::detail::sp_ms_deleter< T > * pd = boost::get_deleter< boost::detail::sp_ms_deleter< T > >( pt );
|
||||
|
||||
void * pv = pd->address();
|
||||
|
||||
@@ -116,9 +137,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 ), detail::sp_ms_deleter< T >(), a );
|
||||
boost::shared_ptr< T > pt( static_cast< T* >( 0 ), BOOST_SP_MSD( T ), a );
|
||||
|
||||
detail::sp_ms_deleter< T > * pd = boost::get_deleter< detail::sp_ms_deleter< T > >( pt );
|
||||
boost::detail::sp_ms_deleter< T > * pd = boost::get_deleter< boost::detail::sp_ms_deleter< T > >( pt );
|
||||
|
||||
void * pv = pd->address();
|
||||
|
||||
@@ -135,15 +156,15 @@ template< class T, class A > boost::shared_ptr< T > allocate_shared( A const & a
|
||||
|
||||
// Variadic templates, rvalue reference
|
||||
|
||||
template< class T, class... Args > boost::shared_ptr< T > make_shared( Args && ... args )
|
||||
template< class T, class Arg1, class... Args > boost::shared_ptr< T > make_shared( Arg1 && arg1, Args && ... args )
|
||||
{
|
||||
boost::shared_ptr< T > pt( static_cast< T* >( 0 ), detail::sp_ms_deleter< T >() );
|
||||
boost::shared_ptr< T > pt( static_cast< T* >( 0 ), BOOST_SP_MSD( T ) );
|
||||
|
||||
detail::sp_ms_deleter< T > * pd = boost::get_deleter< detail::sp_ms_deleter< T > >( pt );
|
||||
boost::detail::sp_ms_deleter< T > * pd = boost::get_deleter< boost::detail::sp_ms_deleter< T > >( pt );
|
||||
|
||||
void * pv = pd->address();
|
||||
|
||||
::new( pv ) T( detail::forward<Args>( args )... );
|
||||
::new( pv ) T( boost::detail::sp_forward<Arg1>( arg1 ), boost::detail::sp_forward<Args>( args )... );
|
||||
pd->set_initialized();
|
||||
|
||||
T * pt2 = static_cast< T* >( pv );
|
||||
@@ -152,15 +173,469 @@ template< class T, class... Args > boost::shared_ptr< T > make_shared( Args && .
|
||||
return boost::shared_ptr< T >( pt, pt2 );
|
||||
}
|
||||
|
||||
template< class T, class A, class... Args > boost::shared_ptr< T > allocate_shared( A const & a, Args && ... args )
|
||||
template< class T, class A, class Arg1, class... Args > boost::shared_ptr< T > allocate_shared( A const & a, Arg1 && arg1, Args && ... args )
|
||||
{
|
||||
boost::shared_ptr< T > pt( static_cast< T* >( 0 ), detail::sp_ms_deleter< T >(), a );
|
||||
boost::shared_ptr< T > pt( static_cast< T* >( 0 ), BOOST_SP_MSD( T ), a );
|
||||
|
||||
detail::sp_ms_deleter< T > * pd = boost::get_deleter< detail::sp_ms_deleter< T > >( pt );
|
||||
boost::detail::sp_ms_deleter< T > * pd = boost::get_deleter< boost::detail::sp_ms_deleter< T > >( pt );
|
||||
|
||||
void * pv = pd->address();
|
||||
|
||||
::new( pv ) T( detail::forward<Args>( args )... );
|
||||
::new( pv ) T( boost::detail::sp_forward<Arg1>( arg1 ), boost::detail::sp_forward<Args>( args )... );
|
||||
pd->set_initialized();
|
||||
|
||||
T * pt2 = static_cast< T* >( pv );
|
||||
|
||||
boost::detail::sp_enable_shared_from_this( &pt, pt2, pt2 );
|
||||
return boost::shared_ptr< T >( pt, pt2 );
|
||||
}
|
||||
|
||||
#elif defined( BOOST_HAS_RVALUE_REFS )
|
||||
|
||||
// For example MSVC 10.0
|
||||
|
||||
template< class T, class A1 >
|
||||
boost::shared_ptr< T > make_shared( A1 && a1 )
|
||||
{
|
||||
boost::shared_ptr< T > pt( static_cast< T* >( 0 ), BOOST_SP_MSD( T ) );
|
||||
|
||||
boost::detail::sp_ms_deleter< T > * pd = boost::get_deleter< boost::detail::sp_ms_deleter< T > >( pt );
|
||||
|
||||
void * pv = pd->address();
|
||||
|
||||
::new( pv ) T(
|
||||
boost::detail::sp_forward<A1>( a1 )
|
||||
);
|
||||
|
||||
pd->set_initialized();
|
||||
|
||||
T * pt2 = static_cast< T* >( pv );
|
||||
|
||||
boost::detail::sp_enable_shared_from_this( &pt, pt2, pt2 );
|
||||
return boost::shared_ptr< T >( pt, pt2 );
|
||||
}
|
||||
|
||||
template< class T, class A, class A1 >
|
||||
boost::shared_ptr< T > allocate_shared( A const & a, A1 && a1 )
|
||||
{
|
||||
boost::shared_ptr< T > pt( static_cast< T* >( 0 ), BOOST_SP_MSD( T ), a );
|
||||
|
||||
boost::detail::sp_ms_deleter< T > * pd = boost::get_deleter< boost::detail::sp_ms_deleter< T > >( pt );
|
||||
|
||||
void * pv = pd->address();
|
||||
|
||||
::new( pv ) T(
|
||||
boost::detail::sp_forward<A1>( a1 )
|
||||
);
|
||||
|
||||
pd->set_initialized();
|
||||
|
||||
T * pt2 = static_cast< T* >( pv );
|
||||
|
||||
boost::detail::sp_enable_shared_from_this( &pt, pt2, pt2 );
|
||||
return boost::shared_ptr< T >( pt, pt2 );
|
||||
}
|
||||
|
||||
template< class T, class A1, class A2 >
|
||||
boost::shared_ptr< T > make_shared( A1 && a1, A2 && a2 )
|
||||
{
|
||||
boost::shared_ptr< T > pt( static_cast< T* >( 0 ), BOOST_SP_MSD( T ) );
|
||||
|
||||
boost::detail::sp_ms_deleter< T > * pd = boost::get_deleter< boost::detail::sp_ms_deleter< T > >( pt );
|
||||
|
||||
void * pv = pd->address();
|
||||
|
||||
::new( pv ) T(
|
||||
boost::detail::sp_forward<A1>( a1 ),
|
||||
boost::detail::sp_forward<A2>( a2 )
|
||||
);
|
||||
|
||||
pd->set_initialized();
|
||||
|
||||
T * pt2 = static_cast< T* >( pv );
|
||||
|
||||
boost::detail::sp_enable_shared_from_this( &pt, pt2, pt2 );
|
||||
return boost::shared_ptr< T >( pt, pt2 );
|
||||
}
|
||||
|
||||
template< class T, class A, class A1, class A2 >
|
||||
boost::shared_ptr< T > allocate_shared( A const & a, A1 && a1, A2 && a2 )
|
||||
{
|
||||
boost::shared_ptr< T > pt( static_cast< T* >( 0 ), BOOST_SP_MSD( T ), a );
|
||||
|
||||
boost::detail::sp_ms_deleter< T > * pd = boost::get_deleter< boost::detail::sp_ms_deleter< T > >( pt );
|
||||
|
||||
void * pv = pd->address();
|
||||
|
||||
::new( pv ) T(
|
||||
boost::detail::sp_forward<A1>( a1 ),
|
||||
boost::detail::sp_forward<A2>( a2 )
|
||||
);
|
||||
|
||||
pd->set_initialized();
|
||||
|
||||
T * pt2 = static_cast< T* >( pv );
|
||||
|
||||
boost::detail::sp_enable_shared_from_this( &pt, pt2, pt2 );
|
||||
return boost::shared_ptr< T >( pt, pt2 );
|
||||
}
|
||||
|
||||
template< class T, class A1, class A2, class A3 >
|
||||
boost::shared_ptr< T > make_shared( A1 && a1, A2 && a2, A3 && a3 )
|
||||
{
|
||||
boost::shared_ptr< T > pt( static_cast< T* >( 0 ), BOOST_SP_MSD( T ) );
|
||||
|
||||
boost::detail::sp_ms_deleter< T > * pd = boost::get_deleter< boost::detail::sp_ms_deleter< T > >( pt );
|
||||
|
||||
void * pv = pd->address();
|
||||
|
||||
::new( pv ) T(
|
||||
boost::detail::sp_forward<A1>( a1 ),
|
||||
boost::detail::sp_forward<A2>( a2 ),
|
||||
boost::detail::sp_forward<A3>( a3 )
|
||||
);
|
||||
|
||||
pd->set_initialized();
|
||||
|
||||
T * pt2 = static_cast< T* >( pv );
|
||||
|
||||
boost::detail::sp_enable_shared_from_this( &pt, pt2, pt2 );
|
||||
return boost::shared_ptr< T >( pt, pt2 );
|
||||
}
|
||||
|
||||
template< class T, class A, class A1, class A2, class A3 >
|
||||
boost::shared_ptr< T > allocate_shared( A const & a, A1 && a1, A2 && a2, A3 && a3 )
|
||||
{
|
||||
boost::shared_ptr< T > pt( static_cast< T* >( 0 ), BOOST_SP_MSD( T ), a );
|
||||
|
||||
boost::detail::sp_ms_deleter< T > * pd = boost::get_deleter< boost::detail::sp_ms_deleter< T > >( pt );
|
||||
|
||||
void * pv = pd->address();
|
||||
|
||||
::new( pv ) T(
|
||||
boost::detail::sp_forward<A1>( a1 ),
|
||||
boost::detail::sp_forward<A2>( a2 ),
|
||||
boost::detail::sp_forward<A3>( a3 )
|
||||
);
|
||||
|
||||
pd->set_initialized();
|
||||
|
||||
T * pt2 = static_cast< T* >( pv );
|
||||
|
||||
boost::detail::sp_enable_shared_from_this( &pt, pt2, pt2 );
|
||||
return boost::shared_ptr< T >( pt, pt2 );
|
||||
}
|
||||
|
||||
template< class T, class A1, class A2, class A3, class A4 >
|
||||
boost::shared_ptr< T > make_shared( A1 && a1, A2 && a2, A3 && a3, A4 && a4 )
|
||||
{
|
||||
boost::shared_ptr< T > pt( static_cast< T* >( 0 ), BOOST_SP_MSD( T ) );
|
||||
|
||||
boost::detail::sp_ms_deleter< T > * pd = boost::get_deleter< boost::detail::sp_ms_deleter< T > >( pt );
|
||||
|
||||
void * pv = pd->address();
|
||||
|
||||
::new( pv ) T(
|
||||
boost::detail::sp_forward<A1>( a1 ),
|
||||
boost::detail::sp_forward<A2>( a2 ),
|
||||
boost::detail::sp_forward<A3>( a3 ),
|
||||
boost::detail::sp_forward<A4>( a4 )
|
||||
);
|
||||
|
||||
pd->set_initialized();
|
||||
|
||||
T * pt2 = static_cast< T* >( pv );
|
||||
|
||||
boost::detail::sp_enable_shared_from_this( &pt, pt2, pt2 );
|
||||
return boost::shared_ptr< T >( pt, pt2 );
|
||||
}
|
||||
|
||||
template< class T, class A, class A1, class A2, class A3, class A4 >
|
||||
boost::shared_ptr< T > allocate_shared( A const & a, A1 && a1, A2 && a2, A3 && a3, A4 && a4 )
|
||||
{
|
||||
boost::shared_ptr< T > pt( static_cast< T* >( 0 ), BOOST_SP_MSD( T ), a );
|
||||
|
||||
boost::detail::sp_ms_deleter< T > * pd = boost::get_deleter< boost::detail::sp_ms_deleter< T > >( pt );
|
||||
|
||||
void * pv = pd->address();
|
||||
|
||||
::new( pv ) T(
|
||||
boost::detail::sp_forward<A1>( a1 ),
|
||||
boost::detail::sp_forward<A2>( a2 ),
|
||||
boost::detail::sp_forward<A3>( a3 ),
|
||||
boost::detail::sp_forward<A4>( a4 )
|
||||
);
|
||||
|
||||
pd->set_initialized();
|
||||
|
||||
T * pt2 = static_cast< T* >( pv );
|
||||
|
||||
boost::detail::sp_enable_shared_from_this( &pt, pt2, pt2 );
|
||||
return boost::shared_ptr< T >( pt, pt2 );
|
||||
}
|
||||
|
||||
template< class T, class A1, class A2, class A3, class A4, class A5 >
|
||||
boost::shared_ptr< T > make_shared( A1 && a1, A2 && a2, A3 && a3, A4 && a4, A5 && a5 )
|
||||
{
|
||||
boost::shared_ptr< T > pt( static_cast< T* >( 0 ), BOOST_SP_MSD( T ) );
|
||||
|
||||
boost::detail::sp_ms_deleter< T > * pd = boost::get_deleter< boost::detail::sp_ms_deleter< T > >( pt );
|
||||
|
||||
void * pv = pd->address();
|
||||
|
||||
::new( pv ) T(
|
||||
boost::detail::sp_forward<A1>( a1 ),
|
||||
boost::detail::sp_forward<A2>( a2 ),
|
||||
boost::detail::sp_forward<A3>( a3 ),
|
||||
boost::detail::sp_forward<A4>( a4 ),
|
||||
boost::detail::sp_forward<A5>( a5 )
|
||||
);
|
||||
|
||||
pd->set_initialized();
|
||||
|
||||
T * pt2 = static_cast< T* >( pv );
|
||||
|
||||
boost::detail::sp_enable_shared_from_this( &pt, pt2, pt2 );
|
||||
return boost::shared_ptr< T >( pt, pt2 );
|
||||
}
|
||||
|
||||
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 && a1, A2 && a2, A3 && a3, A4 && a4, A5 && a5 )
|
||||
{
|
||||
boost::shared_ptr< T > pt( static_cast< T* >( 0 ), BOOST_SP_MSD( T ), a );
|
||||
|
||||
boost::detail::sp_ms_deleter< T > * pd = boost::get_deleter< boost::detail::sp_ms_deleter< T > >( pt );
|
||||
|
||||
void * pv = pd->address();
|
||||
|
||||
::new( pv ) T(
|
||||
boost::detail::sp_forward<A1>( a1 ),
|
||||
boost::detail::sp_forward<A2>( a2 ),
|
||||
boost::detail::sp_forward<A3>( a3 ),
|
||||
boost::detail::sp_forward<A4>( a4 ),
|
||||
boost::detail::sp_forward<A5>( a5 )
|
||||
);
|
||||
|
||||
pd->set_initialized();
|
||||
|
||||
T * pt2 = static_cast< T* >( pv );
|
||||
|
||||
boost::detail::sp_enable_shared_from_this( &pt, pt2, pt2 );
|
||||
return boost::shared_ptr< T >( pt, pt2 );
|
||||
}
|
||||
|
||||
template< class T, class A1, class A2, class A3, class A4, class A5, class A6 >
|
||||
boost::shared_ptr< T > make_shared( A1 && a1, A2 && a2, A3 && a3, A4 && a4, A5 && a5, A6 && a6 )
|
||||
{
|
||||
boost::shared_ptr< T > pt( static_cast< T* >( 0 ), BOOST_SP_MSD( T ) );
|
||||
|
||||
boost::detail::sp_ms_deleter< T > * pd = boost::get_deleter< boost::detail::sp_ms_deleter< T > >( pt );
|
||||
|
||||
void * pv = pd->address();
|
||||
|
||||
::new( pv ) T(
|
||||
boost::detail::sp_forward<A1>( a1 ),
|
||||
boost::detail::sp_forward<A2>( a2 ),
|
||||
boost::detail::sp_forward<A3>( a3 ),
|
||||
boost::detail::sp_forward<A4>( a4 ),
|
||||
boost::detail::sp_forward<A5>( a5 ),
|
||||
boost::detail::sp_forward<A6>( a6 )
|
||||
);
|
||||
|
||||
pd->set_initialized();
|
||||
|
||||
T * pt2 = static_cast< T* >( pv );
|
||||
|
||||
boost::detail::sp_enable_shared_from_this( &pt, pt2, pt2 );
|
||||
return boost::shared_ptr< T >( pt, pt2 );
|
||||
}
|
||||
|
||||
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 && a1, A2 && a2, A3 && a3, A4 && a4, A5 && a5, A6 && a6 )
|
||||
{
|
||||
boost::shared_ptr< T > pt( static_cast< T* >( 0 ), BOOST_SP_MSD( T ), a );
|
||||
|
||||
boost::detail::sp_ms_deleter< T > * pd = boost::get_deleter< boost::detail::sp_ms_deleter< T > >( pt );
|
||||
|
||||
void * pv = pd->address();
|
||||
|
||||
::new( pv ) T(
|
||||
boost::detail::sp_forward<A1>( a1 ),
|
||||
boost::detail::sp_forward<A2>( a2 ),
|
||||
boost::detail::sp_forward<A3>( a3 ),
|
||||
boost::detail::sp_forward<A4>( a4 ),
|
||||
boost::detail::sp_forward<A5>( a5 ),
|
||||
boost::detail::sp_forward<A6>( a6 )
|
||||
);
|
||||
|
||||
pd->set_initialized();
|
||||
|
||||
T * pt2 = static_cast< T* >( pv );
|
||||
|
||||
boost::detail::sp_enable_shared_from_this( &pt, pt2, pt2 );
|
||||
return boost::shared_ptr< T >( pt, pt2 );
|
||||
}
|
||||
|
||||
template< class T, class A1, class A2, class A3, class A4, class A5, class A6, class A7 >
|
||||
boost::shared_ptr< T > make_shared( A1 && a1, A2 && a2, A3 && a3, A4 && a4, A5 && a5, A6 && a6, A7 && a7 )
|
||||
{
|
||||
boost::shared_ptr< T > pt( static_cast< T* >( 0 ), BOOST_SP_MSD( T ) );
|
||||
|
||||
boost::detail::sp_ms_deleter< T > * pd = boost::get_deleter< boost::detail::sp_ms_deleter< T > >( pt );
|
||||
|
||||
void * pv = pd->address();
|
||||
|
||||
::new( pv ) T(
|
||||
boost::detail::sp_forward<A1>( a1 ),
|
||||
boost::detail::sp_forward<A2>( a2 ),
|
||||
boost::detail::sp_forward<A3>( a3 ),
|
||||
boost::detail::sp_forward<A4>( a4 ),
|
||||
boost::detail::sp_forward<A5>( a5 ),
|
||||
boost::detail::sp_forward<A6>( a6 ),
|
||||
boost::detail::sp_forward<A7>( a7 )
|
||||
);
|
||||
|
||||
pd->set_initialized();
|
||||
|
||||
T * pt2 = static_cast< T* >( pv );
|
||||
|
||||
boost::detail::sp_enable_shared_from_this( &pt, pt2, pt2 );
|
||||
return boost::shared_ptr< T >( pt, pt2 );
|
||||
}
|
||||
|
||||
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 && a1, A2 && a2, A3 && a3, A4 && a4, A5 && a5, A6 && a6, A7 && a7 )
|
||||
{
|
||||
boost::shared_ptr< T > pt( static_cast< T* >( 0 ), BOOST_SP_MSD( T ), a );
|
||||
|
||||
boost::detail::sp_ms_deleter< T > * pd = boost::get_deleter< boost::detail::sp_ms_deleter< T > >( pt );
|
||||
|
||||
void * pv = pd->address();
|
||||
|
||||
::new( pv ) T(
|
||||
boost::detail::sp_forward<A1>( a1 ),
|
||||
boost::detail::sp_forward<A2>( a2 ),
|
||||
boost::detail::sp_forward<A3>( a3 ),
|
||||
boost::detail::sp_forward<A4>( a4 ),
|
||||
boost::detail::sp_forward<A5>( a5 ),
|
||||
boost::detail::sp_forward<A6>( a6 ),
|
||||
boost::detail::sp_forward<A7>( a7 )
|
||||
);
|
||||
|
||||
pd->set_initialized();
|
||||
|
||||
T * pt2 = static_cast< T* >( pv );
|
||||
|
||||
boost::detail::sp_enable_shared_from_this( &pt, pt2, pt2 );
|
||||
return boost::shared_ptr< T >( pt, pt2 );
|
||||
}
|
||||
|
||||
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 && a1, A2 && a2, A3 && a3, A4 && a4, A5 && a5, A6 && a6, A7 && a7, A8 && a8 )
|
||||
{
|
||||
boost::shared_ptr< T > pt( static_cast< T* >( 0 ), BOOST_SP_MSD( T ) );
|
||||
|
||||
boost::detail::sp_ms_deleter< T > * pd = boost::get_deleter< boost::detail::sp_ms_deleter< T > >( pt );
|
||||
|
||||
void * pv = pd->address();
|
||||
|
||||
::new( pv ) T(
|
||||
boost::detail::sp_forward<A1>( a1 ),
|
||||
boost::detail::sp_forward<A2>( a2 ),
|
||||
boost::detail::sp_forward<A3>( a3 ),
|
||||
boost::detail::sp_forward<A4>( a4 ),
|
||||
boost::detail::sp_forward<A5>( a5 ),
|
||||
boost::detail::sp_forward<A6>( a6 ),
|
||||
boost::detail::sp_forward<A7>( a7 ),
|
||||
boost::detail::sp_forward<A8>( a8 )
|
||||
);
|
||||
|
||||
pd->set_initialized();
|
||||
|
||||
T * pt2 = static_cast< T* >( pv );
|
||||
|
||||
boost::detail::sp_enable_shared_from_this( &pt, pt2, pt2 );
|
||||
return boost::shared_ptr< T >( pt, pt2 );
|
||||
}
|
||||
|
||||
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 && a1, A2 && a2, A3 && a3, A4 && a4, A5 && a5, A6 && a6, A7 && a7, A8 && a8 )
|
||||
{
|
||||
boost::shared_ptr< T > pt( static_cast< T* >( 0 ), BOOST_SP_MSD( T ), a );
|
||||
|
||||
boost::detail::sp_ms_deleter< T > * pd = boost::get_deleter< boost::detail::sp_ms_deleter< T > >( pt );
|
||||
|
||||
void * pv = pd->address();
|
||||
|
||||
::new( pv ) T(
|
||||
boost::detail::sp_forward<A1>( a1 ),
|
||||
boost::detail::sp_forward<A2>( a2 ),
|
||||
boost::detail::sp_forward<A3>( a3 ),
|
||||
boost::detail::sp_forward<A4>( a4 ),
|
||||
boost::detail::sp_forward<A5>( a5 ),
|
||||
boost::detail::sp_forward<A6>( a6 ),
|
||||
boost::detail::sp_forward<A7>( a7 ),
|
||||
boost::detail::sp_forward<A8>( a8 )
|
||||
);
|
||||
|
||||
pd->set_initialized();
|
||||
|
||||
T * pt2 = static_cast< T* >( pv );
|
||||
|
||||
boost::detail::sp_enable_shared_from_this( &pt, pt2, pt2 );
|
||||
return boost::shared_ptr< T >( pt, pt2 );
|
||||
}
|
||||
|
||||
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 && a1, A2 && a2, A3 && a3, A4 && a4, A5 && a5, A6 && a6, A7 && a7, A8 && a8, A9 && a9 )
|
||||
{
|
||||
boost::shared_ptr< T > pt( static_cast< T* >( 0 ), BOOST_SP_MSD( T ) );
|
||||
|
||||
boost::detail::sp_ms_deleter< T > * pd = boost::get_deleter< boost::detail::sp_ms_deleter< T > >( pt );
|
||||
|
||||
void * pv = pd->address();
|
||||
|
||||
::new( pv ) T(
|
||||
boost::detail::sp_forward<A1>( a1 ),
|
||||
boost::detail::sp_forward<A2>( a2 ),
|
||||
boost::detail::sp_forward<A3>( a3 ),
|
||||
boost::detail::sp_forward<A4>( a4 ),
|
||||
boost::detail::sp_forward<A5>( a5 ),
|
||||
boost::detail::sp_forward<A6>( a6 ),
|
||||
boost::detail::sp_forward<A7>( a7 ),
|
||||
boost::detail::sp_forward<A8>( a8 ),
|
||||
boost::detail::sp_forward<A9>( a9 )
|
||||
);
|
||||
|
||||
pd->set_initialized();
|
||||
|
||||
T * pt2 = static_cast< T* >( pv );
|
||||
|
||||
boost::detail::sp_enable_shared_from_this( &pt, pt2, pt2 );
|
||||
return boost::shared_ptr< T >( pt, pt2 );
|
||||
}
|
||||
|
||||
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 && a1, A2 && a2, A3 && a3, A4 && a4, A5 && a5, A6 && a6, A7 && a7, A8 && a8, A9 && a9 )
|
||||
{
|
||||
boost::shared_ptr< T > pt( static_cast< T* >( 0 ), BOOST_SP_MSD( T ), a );
|
||||
|
||||
boost::detail::sp_ms_deleter< T > * pd = boost::get_deleter< boost::detail::sp_ms_deleter< T > >( pt );
|
||||
|
||||
void * pv = pd->address();
|
||||
|
||||
::new( pv ) T(
|
||||
boost::detail::sp_forward<A1>( a1 ),
|
||||
boost::detail::sp_forward<A2>( a2 ),
|
||||
boost::detail::sp_forward<A3>( a3 ),
|
||||
boost::detail::sp_forward<A4>( a4 ),
|
||||
boost::detail::sp_forward<A5>( a5 ),
|
||||
boost::detail::sp_forward<A6>( a6 ),
|
||||
boost::detail::sp_forward<A7>( a7 ),
|
||||
boost::detail::sp_forward<A8>( a8 ),
|
||||
boost::detail::sp_forward<A9>( a9 )
|
||||
);
|
||||
|
||||
pd->set_initialized();
|
||||
|
||||
T * pt2 = static_cast< T* >( pv );
|
||||
@@ -176,9 +651,9 @@ template< class T, class A, class... Args > boost::shared_ptr< T > allocate_shar
|
||||
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 >() );
|
||||
boost::shared_ptr< T > pt( static_cast< T* >( 0 ), BOOST_SP_MSD( T ) );
|
||||
|
||||
detail::sp_ms_deleter< T > * pd = boost::get_deleter< detail::sp_ms_deleter< T > >( pt );
|
||||
boost::detail::sp_ms_deleter< T > * pd = boost::get_deleter< boost::detail::sp_ms_deleter< T > >( pt );
|
||||
|
||||
void * pv = pd->address();
|
||||
|
||||
@@ -194,9 +669,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 ), detail::sp_ms_deleter< T >(), a );
|
||||
boost::shared_ptr< T > pt( static_cast< T* >( 0 ), BOOST_SP_MSD( T ), a );
|
||||
|
||||
detail::sp_ms_deleter< T > * pd = boost::get_deleter< detail::sp_ms_deleter< T > >( pt );
|
||||
boost::detail::sp_ms_deleter< T > * pd = boost::get_deleter< boost::detail::sp_ms_deleter< T > >( pt );
|
||||
|
||||
void * pv = pd->address();
|
||||
|
||||
@@ -212,9 +687,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 ), detail::sp_ms_deleter< T >() );
|
||||
boost::shared_ptr< T > pt( static_cast< T* >( 0 ), BOOST_SP_MSD( T ) );
|
||||
|
||||
detail::sp_ms_deleter< T > * pd = boost::get_deleter< detail::sp_ms_deleter< T > >( pt );
|
||||
boost::detail::sp_ms_deleter< T > * pd = boost::get_deleter< boost::detail::sp_ms_deleter< T > >( pt );
|
||||
|
||||
void * pv = pd->address();
|
||||
|
||||
@@ -230,9 +705,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 ), detail::sp_ms_deleter< T >(), a );
|
||||
boost::shared_ptr< T > pt( static_cast< T* >( 0 ), BOOST_SP_MSD( T ), a );
|
||||
|
||||
detail::sp_ms_deleter< T > * pd = boost::get_deleter< detail::sp_ms_deleter< T > >( pt );
|
||||
boost::detail::sp_ms_deleter< T > * pd = boost::get_deleter< boost::detail::sp_ms_deleter< T > >( pt );
|
||||
|
||||
void * pv = pd->address();
|
||||
|
||||
@@ -248,9 +723,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 ), detail::sp_ms_deleter< T >() );
|
||||
boost::shared_ptr< T > pt( static_cast< T* >( 0 ), BOOST_SP_MSD( T ) );
|
||||
|
||||
detail::sp_ms_deleter< T > * pd = boost::get_deleter< detail::sp_ms_deleter< T > >( pt );
|
||||
boost::detail::sp_ms_deleter< T > * pd = boost::get_deleter< boost::detail::sp_ms_deleter< T > >( pt );
|
||||
|
||||
void * pv = pd->address();
|
||||
|
||||
@@ -266,9 +741,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 ), detail::sp_ms_deleter< T >(), a );
|
||||
boost::shared_ptr< T > pt( static_cast< T* >( 0 ), BOOST_SP_MSD( T ), a );
|
||||
|
||||
detail::sp_ms_deleter< T > * pd = boost::get_deleter< detail::sp_ms_deleter< T > >( pt );
|
||||
boost::detail::sp_ms_deleter< T > * pd = boost::get_deleter< boost::detail::sp_ms_deleter< T > >( pt );
|
||||
|
||||
void * pv = pd->address();
|
||||
|
||||
@@ -284,9 +759,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 ), detail::sp_ms_deleter< T >() );
|
||||
boost::shared_ptr< T > pt( static_cast< T* >( 0 ), BOOST_SP_MSD( T ) );
|
||||
|
||||
detail::sp_ms_deleter< T > * pd = boost::get_deleter< detail::sp_ms_deleter< T > >( pt );
|
||||
boost::detail::sp_ms_deleter< T > * pd = boost::get_deleter< boost::detail::sp_ms_deleter< T > >( pt );
|
||||
|
||||
void * pv = pd->address();
|
||||
|
||||
@@ -302,9 +777,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 ), detail::sp_ms_deleter< T >(), a );
|
||||
boost::shared_ptr< T > pt( static_cast< T* >( 0 ), BOOST_SP_MSD( T ), a );
|
||||
|
||||
detail::sp_ms_deleter< T > * pd = boost::get_deleter< detail::sp_ms_deleter< T > >( pt );
|
||||
boost::detail::sp_ms_deleter< T > * pd = boost::get_deleter< boost::detail::sp_ms_deleter< T > >( pt );
|
||||
|
||||
void * pv = pd->address();
|
||||
|
||||
@@ -320,9 +795,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 ), detail::sp_ms_deleter< T >() );
|
||||
boost::shared_ptr< T > pt( static_cast< T* >( 0 ), BOOST_SP_MSD( T ) );
|
||||
|
||||
detail::sp_ms_deleter< T > * pd = boost::get_deleter< detail::sp_ms_deleter< T > >( pt );
|
||||
boost::detail::sp_ms_deleter< T > * pd = boost::get_deleter< boost::detail::sp_ms_deleter< T > >( pt );
|
||||
|
||||
void * pv = pd->address();
|
||||
|
||||
@@ -338,9 +813,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 ), detail::sp_ms_deleter< T >(), a );
|
||||
boost::shared_ptr< T > pt( static_cast< T* >( 0 ), BOOST_SP_MSD( T ), a );
|
||||
|
||||
detail::sp_ms_deleter< T > * pd = boost::get_deleter< detail::sp_ms_deleter< T > >( pt );
|
||||
boost::detail::sp_ms_deleter< T > * pd = boost::get_deleter< boost::detail::sp_ms_deleter< T > >( pt );
|
||||
|
||||
void * pv = pd->address();
|
||||
|
||||
@@ -356,9 +831,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 ), detail::sp_ms_deleter< T >() );
|
||||
boost::shared_ptr< T > pt( static_cast< T* >( 0 ), BOOST_SP_MSD( T ) );
|
||||
|
||||
detail::sp_ms_deleter< T > * pd = boost::get_deleter< detail::sp_ms_deleter< T > >( pt );
|
||||
boost::detail::sp_ms_deleter< T > * pd = boost::get_deleter< boost::detail::sp_ms_deleter< T > >( pt );
|
||||
|
||||
void * pv = pd->address();
|
||||
|
||||
@@ -374,9 +849,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 ), detail::sp_ms_deleter< T >(), a );
|
||||
boost::shared_ptr< T > pt( static_cast< T* >( 0 ), BOOST_SP_MSD( T ), a );
|
||||
|
||||
detail::sp_ms_deleter< T > * pd = boost::get_deleter< detail::sp_ms_deleter< T > >( pt );
|
||||
boost::detail::sp_ms_deleter< T > * pd = boost::get_deleter< boost::detail::sp_ms_deleter< T > >( pt );
|
||||
|
||||
void * pv = pd->address();
|
||||
|
||||
@@ -392,9 +867,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 ), detail::sp_ms_deleter< T >() );
|
||||
boost::shared_ptr< T > pt( static_cast< T* >( 0 ), BOOST_SP_MSD( T ) );
|
||||
|
||||
detail::sp_ms_deleter< T > * pd = boost::get_deleter< detail::sp_ms_deleter< T > >( pt );
|
||||
boost::detail::sp_ms_deleter< T > * pd = boost::get_deleter< boost::detail::sp_ms_deleter< T > >( pt );
|
||||
|
||||
void * pv = pd->address();
|
||||
|
||||
@@ -410,9 +885,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 ), detail::sp_ms_deleter< T >(), a );
|
||||
boost::shared_ptr< T > pt( static_cast< T* >( 0 ), BOOST_SP_MSD( T ), a );
|
||||
|
||||
detail::sp_ms_deleter< T > * pd = boost::get_deleter< detail::sp_ms_deleter< T > >( pt );
|
||||
boost::detail::sp_ms_deleter< T > * pd = boost::get_deleter< boost::detail::sp_ms_deleter< T > >( pt );
|
||||
|
||||
void * pv = pd->address();
|
||||
|
||||
@@ -428,9 +903,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 ), detail::sp_ms_deleter< T >() );
|
||||
boost::shared_ptr< T > pt( static_cast< T* >( 0 ), BOOST_SP_MSD( T ) );
|
||||
|
||||
detail::sp_ms_deleter< T > * pd = boost::get_deleter< detail::sp_ms_deleter< T > >( pt );
|
||||
boost::detail::sp_ms_deleter< T > * pd = boost::get_deleter< boost::detail::sp_ms_deleter< T > >( pt );
|
||||
|
||||
void * pv = pd->address();
|
||||
|
||||
@@ -446,9 +921,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 ), detail::sp_ms_deleter< T >(), a );
|
||||
boost::shared_ptr< T > pt( static_cast< T* >( 0 ), BOOST_SP_MSD( T ), a );
|
||||
|
||||
detail::sp_ms_deleter< T > * pd = boost::get_deleter< detail::sp_ms_deleter< T > >( pt );
|
||||
boost::detail::sp_ms_deleter< T > * pd = boost::get_deleter< boost::detail::sp_ms_deleter< T > >( pt );
|
||||
|
||||
void * pv = pd->address();
|
||||
|
||||
@@ -464,9 +939,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 ), detail::sp_ms_deleter< T >() );
|
||||
boost::shared_ptr< T > pt( static_cast< T* >( 0 ), BOOST_SP_MSD( T ) );
|
||||
|
||||
detail::sp_ms_deleter< T > * pd = boost::get_deleter< detail::sp_ms_deleter< T > >( pt );
|
||||
boost::detail::sp_ms_deleter< T > * pd = boost::get_deleter< boost::detail::sp_ms_deleter< T > >( pt );
|
||||
|
||||
void * pv = pd->address();
|
||||
|
||||
@@ -482,9 +957,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 ), detail::sp_ms_deleter< T >(), a );
|
||||
boost::shared_ptr< T > pt( static_cast< T* >( 0 ), BOOST_SP_MSD( T ), a );
|
||||
|
||||
detail::sp_ms_deleter< T > * pd = boost::get_deleter< detail::sp_ms_deleter< T > >( pt );
|
||||
boost::detail::sp_ms_deleter< T > * pd = boost::get_deleter< boost::detail::sp_ms_deleter< T > >( pt );
|
||||
|
||||
void * pv = pd->address();
|
||||
|
||||
@@ -499,6 +974,8 @@ boost::shared_ptr< T > allocate_shared( A const & a, A1 const & a1, A2 const & a
|
||||
|
||||
#endif
|
||||
|
||||
#undef BOOST_SP_MSD
|
||||
|
||||
} // namespace boost
|
||||
|
||||
#endif // #ifndef BOOST_SMART_PTR_MAKE_SHARED_HPP_INCLUDED
|
||||
|
57
include/boost/smart_ptr/owner_less.hpp
Normal file
57
include/boost/smart_ptr/owner_less.hpp
Normal file
@@ -0,0 +1,57 @@
|
||||
#ifndef BOOST_SMART_PTR_OWNER_LESS_HPP_INCLUDED
|
||||
#define BOOST_SMART_PTR_OWNER_LESS_HPP_INCLUDED
|
||||
|
||||
//
|
||||
// owner_less.hpp
|
||||
//
|
||||
// Copyright (c) 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)
|
||||
//
|
||||
// See http://www.boost.org/libs/smart_ptr/smart_ptr.htm for documentation.
|
||||
//
|
||||
|
||||
#include <functional>
|
||||
|
||||
namespace boost
|
||||
{
|
||||
template<typename T> class shared_ptr;
|
||||
template<typename T> class weak_ptr;
|
||||
|
||||
namespace detail
|
||||
{
|
||||
template<typename T, typename U>
|
||||
struct generic_owner_less : public std::binary_function<T, T, bool>
|
||||
{
|
||||
bool operator()(const T &lhs, const T &rhs) const
|
||||
{
|
||||
return lhs.owner_before(rhs);
|
||||
}
|
||||
bool operator()(const T &lhs, const U &rhs) const
|
||||
{
|
||||
return lhs.owner_before(rhs);
|
||||
}
|
||||
bool operator()(const U &lhs, const T &rhs) const
|
||||
{
|
||||
return lhs.owner_before(rhs);
|
||||
}
|
||||
};
|
||||
} // namespace detail
|
||||
|
||||
template<typename T> struct owner_less;
|
||||
|
||||
template<typename T>
|
||||
struct owner_less<shared_ptr<T> >:
|
||||
public detail::generic_owner_less<shared_ptr<T>, weak_ptr<T> >
|
||||
{};
|
||||
|
||||
template<typename T>
|
||||
struct owner_less<weak_ptr<T> >:
|
||||
public detail::generic_owner_less<weak_ptr<T>, shared_ptr<T> >
|
||||
{};
|
||||
|
||||
} // namespace boost
|
||||
|
||||
#endif // #ifndef BOOST_SMART_PTR_OWNER_LESS_HPP_INCLUDED
|
@@ -69,7 +69,25 @@ public:
|
||||
{
|
||||
}
|
||||
|
||||
// generated copy constructor, assignment, destructor are fine
|
||||
// generated copy constructor, destructor are fine...
|
||||
|
||||
#if defined( BOOST_HAS_RVALUE_REFS )
|
||||
|
||||
// ... except in C++0x, move disables the implicit copy
|
||||
|
||||
shared_array( shared_array const & r ): px( r.px ), pn( r.pn ) // never throws
|
||||
{
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
// assignment
|
||||
|
||||
shared_array & operator=( shared_array const & r ) // never throws
|
||||
{
|
||||
this_type( r ).swap( *this );
|
||||
return *this;
|
||||
}
|
||||
|
||||
void reset(T * p = 0)
|
||||
{
|
||||
@@ -113,6 +131,11 @@ public:
|
||||
pn.swap(other.pn);
|
||||
}
|
||||
|
||||
void * _internal_get_deleter( boost::detail::sp_typeinfo const & ti ) const
|
||||
{
|
||||
return pn.get_deleter( ti );
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
T * px; // contained pointer
|
||||
@@ -140,6 +163,11 @@ template<class T> void swap(shared_array<T> & a, shared_array<T> & b) // never t
|
||||
a.swap(b);
|
||||
}
|
||||
|
||||
template< class D, class T > D * get_deleter( shared_array<T> const & p )
|
||||
{
|
||||
return static_cast< D * >( p._internal_get_deleter( BOOST_SP_TYPEID(D) ) );
|
||||
}
|
||||
|
||||
} // namespace boost
|
||||
|
||||
#endif // #if defined(BOOST_NO_MEMBER_TEMPLATES) && !defined(BOOST_MSVC6_MEMBER_TEMPLATES)
|
||||
|
@@ -41,6 +41,7 @@
|
||||
#include <algorithm> // for std::swap
|
||||
#include <functional> // for std::less
|
||||
#include <typeinfo> // for std::bad_cast
|
||||
#include <cstddef> // for std::size_t
|
||||
|
||||
#if !defined(BOOST_NO_IOSTREAM)
|
||||
#if !defined(BOOST_NO_IOSFWD)
|
||||
@@ -50,17 +51,13 @@
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef BOOST_MSVC // moved here to work around VC++ compiler crash
|
||||
# pragma warning(push)
|
||||
# pragma warning(disable:4284) // odd return type for operator->
|
||||
#endif
|
||||
|
||||
namespace 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
|
||||
{
|
||||
@@ -109,6 +106,14 @@ 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
|
||||
@@ -198,7 +203,17 @@ public:
|
||||
boost::detail::sp_enable_shared_from_this( this, p, p );
|
||||
}
|
||||
|
||||
// generated copy constructor, destructor are fine
|
||||
// generated copy constructor, destructor are fine...
|
||||
|
||||
#if defined( BOOST_HAS_RVALUE_REFS )
|
||||
|
||||
// ... except in C++0x, move disables the implicit copy
|
||||
|
||||
shared_ptr( shared_ptr const & r ): px( r.px ), pn( r.pn ) // never throws
|
||||
{
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
template<class Y>
|
||||
explicit shared_ptr(weak_ptr<Y> const & r): pn(r.pn) // may throw
|
||||
@@ -219,7 +234,7 @@ public:
|
||||
template<class Y>
|
||||
#if !defined( BOOST_SP_NO_SP_CONVERTIBLE )
|
||||
|
||||
shared_ptr( shared_ptr<Y> const & r, typename detail::sp_enable_if_convertible<Y,T>::type = detail::sp_empty() )
|
||||
shared_ptr( shared_ptr<Y> const & r, typename boost::detail::sp_enable_if_convertible<Y,T>::type = boost::detail::sp_empty() )
|
||||
|
||||
#else
|
||||
|
||||
@@ -344,7 +359,7 @@ public:
|
||||
template<class Y>
|
||||
#if !defined( BOOST_SP_NO_SP_CONVERTIBLE )
|
||||
|
||||
shared_ptr( shared_ptr<Y> && r, typename detail::sp_enable_if_convertible<Y,T>::type = detail::sp_empty() )
|
||||
shared_ptr( shared_ptr<Y> && r, typename boost::detail::sp_enable_if_convertible<Y,T>::type = boost::detail::sp_empty() )
|
||||
|
||||
#else
|
||||
|
||||
@@ -434,12 +449,17 @@ public:
|
||||
pn.swap(other.pn);
|
||||
}
|
||||
|
||||
template<class Y> bool _internal_less(shared_ptr<Y> const & rhs) const
|
||||
template<class Y> bool owner_before( shared_ptr<Y> const & rhs ) const
|
||||
{
|
||||
return pn < rhs.pn;
|
||||
}
|
||||
|
||||
void * _internal_get_deleter( detail::sp_typeinfo const & ti ) const
|
||||
template<class Y> bool owner_before( weak_ptr<Y> const & rhs ) const
|
||||
{
|
||||
return pn < rhs.pn;
|
||||
}
|
||||
|
||||
void * _internal_get_deleter( boost::detail::sp_typeinfo const & ti ) const
|
||||
{
|
||||
return pn.get_deleter( ti );
|
||||
}
|
||||
@@ -490,7 +510,7 @@ template<class T> inline bool operator!=(shared_ptr<T> const & a, shared_ptr<T>
|
||||
|
||||
template<class T, class U> inline bool operator<(shared_ptr<T> const & a, shared_ptr<U> const & b)
|
||||
{
|
||||
return a._internal_less(b);
|
||||
return a.owner_before( b );
|
||||
}
|
||||
|
||||
template<class T> inline void swap(shared_ptr<T> & a, shared_ptr<T> & b)
|
||||
@@ -679,14 +699,19 @@ template<class T> inline bool atomic_compare_exchange_explicit( shared_ptr<T> *
|
||||
return atomic_compare_exchange( p, v, w ); // std::move( w )
|
||||
}
|
||||
|
||||
#endif
|
||||
#endif // !defined(BOOST_SP_NO_ATOMIC_ACCESS)
|
||||
|
||||
// hash_value
|
||||
|
||||
template< class T > struct hash;
|
||||
|
||||
template< class T > std::size_t hash_value( boost::shared_ptr<T> const & p )
|
||||
{
|
||||
return boost::hash< T* >()( p.get() );
|
||||
}
|
||||
|
||||
} // namespace boost
|
||||
|
||||
#ifdef BOOST_MSVC
|
||||
# pragma warning(pop)
|
||||
#endif
|
||||
|
||||
#endif // #if defined(BOOST_NO_MEMBER_TEMPLATES) && !defined(BOOST_MSVC6_MEMBER_TEMPLATES)
|
||||
|
||||
#endif // #ifndef BOOST_SMART_PTR_SHARED_PTR_HPP_INCLUDED
|
||||
|
@@ -17,11 +17,6 @@
|
||||
#include <boost/smart_ptr/detail/shared_count.hpp>
|
||||
#include <boost/smart_ptr/shared_ptr.hpp>
|
||||
|
||||
#ifdef BOOST_MSVC // moved here to work around VC++ compiler crash
|
||||
# pragma warning(push)
|
||||
# pragma warning(disable:4284) // odd return type for operator->
|
||||
#endif
|
||||
|
||||
namespace boost
|
||||
{
|
||||
|
||||
@@ -40,8 +35,24 @@ public:
|
||||
{
|
||||
}
|
||||
|
||||
// generated copy constructor, assignment, destructor are fine
|
||||
// generated copy constructor, assignment, destructor are fine...
|
||||
|
||||
#if defined( BOOST_HAS_RVALUE_REFS )
|
||||
|
||||
// ... except in C++0x, move disables the implicit copy
|
||||
|
||||
weak_ptr( weak_ptr const & r ): px( r.px ), pn( r.pn ) // never throws
|
||||
{
|
||||
}
|
||||
|
||||
weak_ptr & operator=( weak_ptr const & r ) // never throws
|
||||
{
|
||||
px = r.px;
|
||||
pn = r.pn;
|
||||
return *this;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
//
|
||||
// The "obvious" converting constructor implementation:
|
||||
@@ -63,22 +74,54 @@ public:
|
||||
template<class Y>
|
||||
#if !defined( BOOST_SP_NO_SP_CONVERTIBLE )
|
||||
|
||||
weak_ptr( weak_ptr<Y> const & r, typename detail::sp_enable_if_convertible<Y,T>::type = detail::sp_empty() )
|
||||
weak_ptr( weak_ptr<Y> const & r, typename boost::detail::sp_enable_if_convertible<Y,T>::type = boost::detail::sp_empty() )
|
||||
|
||||
#else
|
||||
|
||||
weak_ptr( weak_ptr<Y> const & r )
|
||||
|
||||
#endif
|
||||
: pn(r.pn) // never throws
|
||||
: px(r.lock().get()), 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( shared_ptr<Y> const & r, typename detail::sp_enable_if_convertible<Y,T>::type = detail::sp_empty() )
|
||||
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() )
|
||||
|
||||
#else
|
||||
|
||||
@@ -99,6 +142,17 @@ 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
|
||||
{
|
||||
@@ -124,6 +178,11 @@ 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);
|
||||
@@ -141,7 +200,12 @@ public:
|
||||
pn = pn2;
|
||||
}
|
||||
|
||||
template<class Y> bool _internal_less(weak_ptr<Y> const & rhs) const
|
||||
template<class Y> bool owner_before( weak_ptr<Y> const & rhs ) const
|
||||
{
|
||||
return pn < rhs.pn;
|
||||
}
|
||||
|
||||
template<class Y> bool owner_before( shared_ptr<Y> const & rhs ) const
|
||||
{
|
||||
return pn < rhs.pn;
|
||||
}
|
||||
@@ -165,7 +229,7 @@ private:
|
||||
|
||||
template<class T, class U> inline bool operator<(weak_ptr<T> const & a, weak_ptr<U> const & b)
|
||||
{
|
||||
return a._internal_less(b);
|
||||
return a.owner_before( b );
|
||||
}
|
||||
|
||||
template<class T> void swap(weak_ptr<T> & a, weak_ptr<T> & b)
|
||||
@@ -175,8 +239,4 @@ template<class T> void swap(weak_ptr<T> & a, weak_ptr<T> & b)
|
||||
|
||||
} // namespace boost
|
||||
|
||||
#ifdef BOOST_MSVC
|
||||
# pragma warning(pop)
|
||||
#endif
|
||||
|
||||
#endif // #ifndef BOOST_SMART_PTR_WEAK_PTR_HPP_INCLUDED
|
||||
|
@@ -1 +0,0 @@
|
||||
boost_module(smart_ptr DEPENDS utility)
|
@@ -1,18 +0,0 @@
|
||||
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)
|
@@ -16,9 +16,11 @@ 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 ]
|
||||
@@ -43,6 +45,7 @@ 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 ]
|
||||
@@ -56,7 +59,14 @@ 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 ]
|
||||
[ run sp_hash_test.cpp ]
|
||||
[ run get_deleter_array_test.cpp ]
|
||||
[ run ip_hash_test.cpp ]
|
||||
[ run owner_less_test.cpp ]
|
||||
;
|
||||
}
|
||||
|
169
test/esft_constructor_test.cpp
Normal file
169
test/esft_constructor_test.cpp
Normal file
@@ -0,0 +1,169 @@
|
||||
//
|
||||
// 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();
|
||||
}
|
95
test/get_deleter_array_test.cpp
Normal file
95
test/get_deleter_array_test.cpp
Normal file
@@ -0,0 +1,95 @@
|
||||
//
|
||||
// get_deleter_array_test.cpp
|
||||
//
|
||||
// Copyright (c) 2002, 2011 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/shared_array.hpp>
|
||||
#include <boost/detail/lightweight_test.hpp>
|
||||
|
||||
struct deleter
|
||||
{
|
||||
int data;
|
||||
|
||||
deleter(): data(0)
|
||||
{
|
||||
}
|
||||
|
||||
void operator()(void *)
|
||||
{
|
||||
BOOST_TEST(data == 17041);
|
||||
}
|
||||
};
|
||||
|
||||
struct deleter2
|
||||
{
|
||||
};
|
||||
|
||||
struct X
|
||||
{
|
||||
};
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
boost::shared_array<X> p;
|
||||
|
||||
BOOST_TEST(boost::get_deleter<void>(p) == 0);
|
||||
BOOST_TEST(boost::get_deleter<void const>(p) == 0);
|
||||
BOOST_TEST(boost::get_deleter<int>(p) == 0);
|
||||
BOOST_TEST(boost::get_deleter<int const>(p) == 0);
|
||||
BOOST_TEST(boost::get_deleter<X>(p) == 0);
|
||||
BOOST_TEST(boost::get_deleter<X const>(p) == 0);
|
||||
BOOST_TEST(boost::get_deleter<deleter>(p) == 0);
|
||||
BOOST_TEST(boost::get_deleter<deleter const>(p) == 0);
|
||||
BOOST_TEST(boost::get_deleter<deleter2>(p) == 0);
|
||||
BOOST_TEST(boost::get_deleter<deleter2 const>(p) == 0);
|
||||
}
|
||||
|
||||
{
|
||||
boost::shared_array<X> p(new X[1]);
|
||||
|
||||
BOOST_TEST(boost::get_deleter<void>(p) == 0);
|
||||
BOOST_TEST(boost::get_deleter<void const>(p) == 0);
|
||||
BOOST_TEST(boost::get_deleter<int>(p) == 0);
|
||||
BOOST_TEST(boost::get_deleter<int const>(p) == 0);
|
||||
BOOST_TEST(boost::get_deleter<X>(p) == 0);
|
||||
BOOST_TEST(boost::get_deleter<X const>(p) == 0);
|
||||
BOOST_TEST(boost::get_deleter<deleter>(p) == 0);
|
||||
BOOST_TEST(boost::get_deleter<deleter const>(p) == 0);
|
||||
BOOST_TEST(boost::get_deleter<deleter2>(p) == 0);
|
||||
BOOST_TEST(boost::get_deleter<deleter2 const>(p) == 0);
|
||||
}
|
||||
|
||||
{
|
||||
X x[1];
|
||||
boost::shared_array<X> p(x, deleter());
|
||||
|
||||
BOOST_TEST(boost::get_deleter<void>(p) == 0);
|
||||
BOOST_TEST(boost::get_deleter<void const>(p) == 0);
|
||||
BOOST_TEST(boost::get_deleter<int>(p) == 0);
|
||||
BOOST_TEST(boost::get_deleter<int const>(p) == 0);
|
||||
BOOST_TEST(boost::get_deleter<X>(p) == 0);
|
||||
BOOST_TEST(boost::get_deleter<X const>(p) == 0);
|
||||
BOOST_TEST(boost::get_deleter<deleter2>(p) == 0);
|
||||
BOOST_TEST(boost::get_deleter<deleter2 const>(p) == 0);
|
||||
|
||||
deleter * q = boost::get_deleter<deleter>(p);
|
||||
|
||||
BOOST_TEST(q != 0);
|
||||
BOOST_TEST(q->data == 0);
|
||||
|
||||
q->data = 17041;
|
||||
|
||||
deleter const * r = boost::get_deleter<deleter const>(p);
|
||||
|
||||
BOOST_TEST(r == q);
|
||||
BOOST_TEST(r->data == 17041);
|
||||
}
|
||||
|
||||
return boost::report_errors();
|
||||
}
|
183
test/intrusive_ptr_move_test.cpp
Normal file
183
test/intrusive_ptr_move_test.cpp
Normal file
@@ -0,0 +1,183 @@
|
||||
#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 <utility>
|
||||
|
||||
#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
|
75
test/ip_hash_test.cpp
Normal file
75
test/ip_hash_test.cpp
Normal file
@@ -0,0 +1,75 @@
|
||||
//
|
||||
// ip_hash_test.cpp
|
||||
//
|
||||
// Copyright 2011 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/intrusive_ptr.hpp>
|
||||
#include <boost/functional/hash.hpp>
|
||||
#include <boost/detail/lightweight_test.hpp>
|
||||
|
||||
class base
|
||||
{
|
||||
private:
|
||||
|
||||
int use_count_;
|
||||
|
||||
base(base const &);
|
||||
base & operator=(base const &);
|
||||
|
||||
protected:
|
||||
|
||||
base(): use_count_(0)
|
||||
{
|
||||
}
|
||||
|
||||
virtual ~base()
|
||||
{
|
||||
}
|
||||
|
||||
public:
|
||||
|
||||
long use_count() const
|
||||
{
|
||||
return use_count_;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
};
|
||||
|
||||
struct X: public base
|
||||
{
|
||||
};
|
||||
|
||||
int main()
|
||||
{
|
||||
boost::hash< boost::intrusive_ptr<X> > hasher;
|
||||
|
||||
boost::intrusive_ptr<X> p1, p2( p1 ), p3( new X ), p4( p3 ), p5( new X );
|
||||
|
||||
BOOST_TEST_EQ( p1, p2 );
|
||||
BOOST_TEST_EQ( hasher( p1 ), hasher( p2 ) );
|
||||
|
||||
BOOST_TEST_NE( p1, p3 );
|
||||
BOOST_TEST_NE( hasher( p1 ), hasher( p3 ) );
|
||||
|
||||
BOOST_TEST_EQ( p3, p4 );
|
||||
BOOST_TEST_EQ( hasher( p3 ), hasher( p4 ) );
|
||||
|
||||
BOOST_TEST_NE( p3, p5 );
|
||||
BOOST_TEST_NE( hasher( p3 ), hasher( p5 ) );
|
||||
|
||||
return boost::report_errors();
|
||||
}
|
19
test/make_shared_fp_test.cpp
Normal file
19
test/make_shared_fp_test.cpp
Normal file
@@ -0,0 +1,19 @@
|
||||
//
|
||||
// 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>;
|
||||
}
|
98
test/make_shared_perfect_forwarding_test.cpp
Normal file
98
test/make_shared_perfect_forwarding_test.cpp
Normal file
@@ -0,0 +1,98 @@
|
||||
// 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 )
|
||||
|
||||
int main()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
#else // BOOST_HAS_RVALUE_REFS
|
||||
|
||||
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
|
67
test/owner_less_test.cpp
Normal file
67
test/owner_less_test.cpp
Normal file
@@ -0,0 +1,67 @@
|
||||
//
|
||||
// owner_less_test.cpp
|
||||
//
|
||||
// A regression test for owner_less
|
||||
//
|
||||
// Copyright (c) 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/detail/lightweight_test.hpp>
|
||||
#include <boost/smart_ptr/owner_less.hpp>
|
||||
#include <boost/shared_ptr.hpp>
|
||||
#include <boost/weak_ptr.hpp>
|
||||
|
||||
int main()
|
||||
{
|
||||
boost::owner_less<boost::shared_ptr<int> > comp;
|
||||
{
|
||||
boost::shared_ptr<int> x;
|
||||
boost::shared_ptr<int> y;
|
||||
boost::weak_ptr<int> w;
|
||||
BOOST_TEST(!(comp(x, w) || comp(w, x)));
|
||||
}
|
||||
{
|
||||
boost::shared_ptr<int> z((int*)0);
|
||||
boost::weak_ptr<int> w;
|
||||
BOOST_TEST(comp(z, w) || comp(w, z));
|
||||
{
|
||||
boost::shared_ptr<int> zz(z);
|
||||
w = boost::weak_ptr<int>(zz);
|
||||
BOOST_TEST(!(comp(z, zz) || comp(z, zz)));
|
||||
BOOST_TEST(!(comp(z, w) || comp(z, w)));
|
||||
}
|
||||
BOOST_TEST(!(comp(z, w) || comp(w, z)));
|
||||
}
|
||||
{
|
||||
boost::shared_ptr<int> x;
|
||||
boost::shared_ptr<int> z((int*)0);
|
||||
BOOST_TEST(comp(x, z) || comp(z, x));
|
||||
}
|
||||
{
|
||||
boost::shared_ptr<int> a((int*)0);
|
||||
boost::shared_ptr<int> b((int*)0);
|
||||
BOOST_TEST(comp(a, b) || comp(b, a));
|
||||
boost::weak_ptr<int> w(a);
|
||||
BOOST_TEST(!(comp(a, w) || comp(w, a)));
|
||||
BOOST_TEST(comp(b, w) || comp(w, b));
|
||||
}
|
||||
|
||||
boost::owner_less<boost::weak_ptr<int> > weak_comp;
|
||||
{
|
||||
boost::shared_ptr<int> a((int*)0);
|
||||
boost::weak_ptr<int> wa(a);
|
||||
boost::shared_ptr<int> b((int*)0);
|
||||
boost::weak_ptr<int> wb(b);
|
||||
BOOST_TEST(!(weak_comp(a, wa) || weak_comp(wa, a)));
|
||||
BOOST_TEST(!(weak_comp(b, wb) || weak_comp(wb, b)));
|
||||
BOOST_TEST(weak_comp(wa, wb) || weak_comp(wb, wa));
|
||||
BOOST_TEST(weak_comp(wa, b) || weak_comp(b, wa));
|
||||
}
|
||||
|
||||
return boost::report_errors();
|
||||
}
|
@@ -9,6 +9,8 @@
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
|
||||
#include <boost/config.hpp>
|
||||
|
||||
#include <boost/pointer_cast.hpp>
|
||||
|
||||
#include <boost/shared_ptr.hpp>
|
||||
@@ -58,6 +60,8 @@ 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)
|
||||
{
|
||||
@@ -74,6 +78,8 @@ 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)
|
||||
{
|
||||
@@ -107,7 +113,9 @@ 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 ) );
|
||||
}
|
||||
@@ -117,7 +125,9 @@ 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() ) );
|
||||
}
|
||||
|
@@ -63,10 +63,12 @@ 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& )
|
||||
{
|
||||
|
@@ -188,6 +188,7 @@ 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);
|
||||
|
||||
@@ -201,6 +202,7 @@ int main()
|
||||
test_is_Y(p3);
|
||||
test_eq2(p, p3);
|
||||
test_ne2(p2, p4);
|
||||
#endif
|
||||
|
||||
shared_ptr<void> p5(p);
|
||||
|
||||
@@ -214,13 +216,17 @@ 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);
|
||||
|
||||
@@ -250,6 +256,7 @@ 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);
|
||||
@@ -259,12 +266,15 @@ 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);
|
||||
@@ -279,7 +289,9 @@ 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
|
||||
|
@@ -8,10 +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>
|
||||
#include <utility>
|
||||
|
||||
#if defined( BOOST_HAS_RVALUE_REFS )
|
||||
|
||||
struct X
|
||||
{
|
||||
@@ -43,11 +44,11 @@ int main()
|
||||
boost::shared_ptr<X> p( new X );
|
||||
BOOST_TEST( X::instances == 1 );
|
||||
|
||||
boost::shared_ptr<X> p2( static_cast< boost::shared_ptr<X> && >( p ) );
|
||||
boost::shared_ptr<X> p2( std::move( p ) );
|
||||
BOOST_TEST( X::instances == 1 );
|
||||
BOOST_TEST( p.get() == 0 );
|
||||
|
||||
boost::shared_ptr<void> p3( static_cast< boost::shared_ptr<X> && >( p2 ) );
|
||||
boost::shared_ptr<void> p3( std::move( p2 ) );
|
||||
BOOST_TEST( X::instances == 1 );
|
||||
BOOST_TEST( p2.get() == 0 );
|
||||
|
||||
@@ -60,12 +61,12 @@ int main()
|
||||
BOOST_TEST( X::instances == 1 );
|
||||
|
||||
boost::shared_ptr<X> p2;
|
||||
p2 = static_cast< boost::shared_ptr<X> && >( p );
|
||||
p2 = std::move( p );
|
||||
BOOST_TEST( X::instances == 1 );
|
||||
BOOST_TEST( p.get() == 0 );
|
||||
|
||||
boost::shared_ptr<void> p3;
|
||||
p3 = static_cast< boost::shared_ptr<X> && >( p2 );
|
||||
p3 = std::move( p2 );
|
||||
BOOST_TEST( X::instances == 1 );
|
||||
BOOST_TEST( p2.get() == 0 );
|
||||
|
||||
@@ -79,13 +80,13 @@ int main()
|
||||
|
||||
boost::shared_ptr<X> p2( new X );
|
||||
BOOST_TEST( X::instances == 2 );
|
||||
p2 = static_cast< boost::shared_ptr<X> && >( p );
|
||||
p2 = std::move( p );
|
||||
BOOST_TEST( X::instances == 1 );
|
||||
BOOST_TEST( p.get() == 0 );
|
||||
|
||||
boost::shared_ptr<void> p3( new X );
|
||||
BOOST_TEST( X::instances == 2 );
|
||||
p3 = static_cast< boost::shared_ptr<X> && >( p2 );
|
||||
p3 = std::move( p2 );
|
||||
BOOST_TEST( X::instances == 1 );
|
||||
BOOST_TEST( p2.get() == 0 );
|
||||
|
||||
|
@@ -2462,6 +2462,8 @@ void test()
|
||||
|
||||
} // namespace n_const_cast
|
||||
|
||||
#if !defined( BOOST_NO_RTTI )
|
||||
|
||||
namespace n_dynamic_cast
|
||||
{
|
||||
|
||||
@@ -2527,6 +2529,8 @@ void test()
|
||||
|
||||
} // namespace n_dynamic_cast
|
||||
|
||||
#endif
|
||||
|
||||
namespace n_map
|
||||
{
|
||||
|
||||
@@ -3200,10 +3204,12 @@ 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
|
||||
@@ -3229,7 +3235,9 @@ 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();
|
||||
|
||||
|
@@ -33,10 +33,7 @@
|
||||
# pragma warn -8092 // template argument passed to 'find' is not an iterator
|
||||
#endif
|
||||
|
||||
#include <boost/scoped_ptr.hpp>
|
||||
#include <boost/scoped_array.hpp>
|
||||
#include <boost/shared_ptr.hpp>
|
||||
#include <boost/shared_array.hpp>
|
||||
#include <boost/smart_ptr.hpp>
|
||||
|
||||
#include <boost/detail/lightweight_test.hpp>
|
||||
|
||||
|
34
test/sp_hash_test.cpp
Normal file
34
test/sp_hash_test.cpp
Normal file
@@ -0,0 +1,34 @@
|
||||
//
|
||||
// sp_hash_test.cpp
|
||||
//
|
||||
// Copyright 2011 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/shared_ptr.hpp>
|
||||
#include <boost/functional/hash.hpp>
|
||||
#include <boost/detail/lightweight_test.hpp>
|
||||
|
||||
int main()
|
||||
{
|
||||
boost::hash< boost::shared_ptr<int> > hasher;
|
||||
|
||||
boost::shared_ptr< int > p1, p2( p1 ), p3( new int ), p4( p3 ), p5( new int );
|
||||
|
||||
BOOST_TEST_EQ( p1, p2 );
|
||||
BOOST_TEST_EQ( hasher( p1 ), hasher( p2 ) );
|
||||
|
||||
BOOST_TEST_NE( p1, p3 );
|
||||
BOOST_TEST_NE( hasher( p1 ), hasher( p3 ) );
|
||||
|
||||
BOOST_TEST_EQ( p3, p4 );
|
||||
BOOST_TEST_EQ( hasher( p3 ), hasher( p4 ) );
|
||||
|
||||
BOOST_TEST_NE( p3, p5 );
|
||||
BOOST_TEST_NE( hasher( p3 ), hasher( p5 ) );
|
||||
|
||||
return boost::report_errors();
|
||||
}
|
51
test/sp_typeinfo_test.cpp
Normal file
51
test/sp_typeinfo_test.cpp
Normal file
@@ -0,0 +1,51 @@
|
||||
//
|
||||
// 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();
|
||||
}
|
122
test/weak_ptr_move_test.cpp
Normal file
122
test/weak_ptr_move_test.cpp
Normal file
@@ -0,0 +1,122 @@
|
||||
//
|
||||
// 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>
|
||||
#include <utility>
|
||||
|
||||
#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
|
@@ -914,7 +914,6 @@ 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);
|
||||
@@ -950,7 +949,6 @@ 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);
|
||||
@@ -965,7 +963,6 @@ 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);
|
||||
|
Reference in New Issue
Block a user