|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r55479 - in branches/release: . boost/graph boost/smart_ptr boost/smart_ptr/detail libs/smart_ptr/test status
From: pdimov_at_[hidden]
Date: 2009-08-08 19:21:17
Author: pdimov
Date: 2009-08-08 19:21:15 EDT (Sat, 08 Aug 2009)
New Revision: 55479
URL: http://svn.boost.org/trac/boost/changeset/55479
Log:
Merge [51909], [51912], [52937], [53672] to release.
Added:
branches/release/boost/smart_ptr/enable_shared_from_this2.hpp
- copied, changed from r51909, /trunk/boost/smart_ptr/enable_shared_from_this2.hpp
branches/release/libs/smart_ptr/test/esft_constructor_test.cpp
- copied unchanged from r51912, /trunk/libs/smart_ptr/test/esft_constructor_test.cpp
branches/release/libs/smart_ptr/test/intrusive_ptr_move_test.cpp
- copied unchanged from r52937, /trunk/libs/smart_ptr/test/intrusive_ptr_move_test.cpp
branches/release/libs/smart_ptr/test/weak_ptr_move_test.cpp
- copied unchanged from r52937, /trunk/libs/smart_ptr/test/weak_ptr_move_test.cpp
Properties modified:
branches/release/ (props changed)
branches/release/boost/graph/ (props changed)
branches/release/status/ (props changed)
Text files modified:
branches/release/boost/smart_ptr/detail/shared_count.hpp | 14 ++++
branches/release/boost/smart_ptr/detail/sp_convertible.hpp | 2
branches/release/boost/smart_ptr/enable_shared_from_this2.hpp | 134 +++++++++++++++++++--------------------
branches/release/boost/smart_ptr/intrusive_ptr.hpp | 17 +++++
branches/release/boost/smart_ptr/shared_ptr.hpp | 13 +++
branches/release/boost/smart_ptr/weak_ptr.hpp | 52 ++++++++++++++
branches/release/libs/smart_ptr/test/Jamfile.v2 | 3
branches/release/libs/smart_ptr/test/shared_ptr_move_test.cpp | 16 ++--
8 files changed, 170 insertions(+), 81 deletions(-)
Modified: branches/release/boost/smart_ptr/detail/shared_count.hpp
==============================================================================
--- branches/release/boost/smart_ptr/detail/shared_count.hpp (original)
+++ branches/release/boost/smart_ptr/detail/shared_count.hpp 2009-08-08 19:21:15 EDT (Sat, 08 Aug 2009)
@@ -333,6 +333,20 @@
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();
Modified: branches/release/boost/smart_ptr/detail/sp_convertible.hpp
==============================================================================
--- branches/release/boost/smart_ptr/detail/sp_convertible.hpp (original)
+++ branches/release/boost/smart_ptr/detail/sp_convertible.hpp 2009-08-08 19:21:15 EDT (Sat, 08 Aug 2009)
@@ -45,7 +45,7 @@
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
Copied: branches/release/boost/smart_ptr/enable_shared_from_this2.hpp (from r51909, /trunk/boost/smart_ptr/enable_shared_from_this2.hpp)
==============================================================================
--- /trunk/boost/smart_ptr/enable_shared_from_this2.hpp (original)
+++ branches/release/boost/smart_ptr/enable_shared_from_this2.hpp 2009-08-08 19:21:15 EDT (Sat, 08 Aug 2009)
@@ -1,16 +1,15 @@
-#ifndef BOOST_ENABLE_SHARED_FROM_THIS_HPP_INCLUDED
-#define BOOST_ENABLE_SHARED_FROM_THIS_HPP_INCLUDED
+#ifndef BOOST_ENABLE_SHARED_FROM_THIS2_HPP_INCLUDED
+#define BOOST_ENABLE_SHARED_FROM_THIS2_HPP_INCLUDED
//
-// enable_shared_from_this.hpp
+// enable_shared_from_this2.hpp
//
-// Copyright (c) 2002 Peter Dimov
+// 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)
-//
-// http://www.boost.org/libs/smart_ptr/enable_shared_from_this.html
+// 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>
@@ -21,114 +20,113 @@
namespace boost
{
-#if !defined( BOOST_NO_MEMBER_TEMPLATE_FRIENDS )
+namespace detail
+{
+
+class esft2_deleter_wrapper
+{
+private:
+
+ shared_ptr<void> deleter_;
-template< class T > class enable_shared_from_this;
-template< class T, class Y > void sp_accept_owner( shared_ptr<Y> * ptr, enable_shared_from_this<T> const * pe );
-template< class T, class Y > void sp_accept_owner( shared_ptr<Y> * ptr, enable_shared_from_this<T> const * pe, void * /*pd*/ );
+public:
-#endif
+ esft2_deleter_wrapper()
+ {
+ }
-template< class T > class enable_shared_from_this
+ 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_this()
+ enable_shared_from_this2()
{
}
- enable_shared_from_this(enable_shared_from_this const &)
+ enable_shared_from_this2( enable_shared_from_this2 const & )
{
}
- enable_shared_from_this & operator=(enable_shared_from_this const &)
+ enable_shared_from_this2 & operator=( enable_shared_from_this2 const & )
{
return *this;
}
-// virtual destructor because we need a vtable for dynamic_cast from base to derived to work
- virtual ~enable_shared_from_this()
+ ~enable_shared_from_this2()
{
- BOOST_ASSERT( _shared_count.use_count() <= 1 ); // make sure no dangling shared_ptr objects exist
+ 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();
- T * p = dynamic_cast<T *>( this );
- return shared_ptr<T>( detail::shared_count( _weak_count ), p );
+ return shared_ptr<T>( weak_this_ );
}
shared_ptr<T const> shared_from_this() const
{
init_weak_once();
- T const * p = dynamic_cast<T const *>( this );
- return shared_ptr<T const>( detail::shared_count( _weak_count ), p );
+ return shared_ptr<T>( weak_this_ );
}
private:
- mutable detail::weak_count _weak_count;
- mutable detail::shared_count _shared_count;
-
void init_weak_once() const
{
- if( _weak_count.empty() )
+ if( weak_this_._empty() )
{
- detail::shared_count( (void*)0, detail::sp_deleter_wrapper() ).swap( _shared_count );
- _weak_count = _shared_count;
+ shared_this_.reset( static_cast< T* >( 0 ), detail::esft2_deleter_wrapper() );
+ weak_this_ = shared_this_;
}
}
-#if !defined( BOOST_NO_MEMBER_TEMPLATE_FRIENDS )
-
- template< class U, class Y > friend void sp_accept_owner( shared_ptr<Y> * ptr, enable_shared_from_this<U> const * pe );
- template< class U, class Y > friend void sp_accept_owner( shared_ptr<Y> * ptr, enable_shared_from_this<U> const * pe, void * /*pd*/ );
+public: // actually private, but avoids compiler template friendship issues
-#else
-
-public:
-
-#endif
-
- template<typename U>
- void sp_accept_owner( shared_ptr<U> & owner ) const
+ // 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
{
- if( _weak_count.use_count() == 0 )
+ BOOST_ASSERT( ppx != 0 );
+
+ if( weak_this_.use_count() == 0 )
{
- _weak_count = owner.get_shared_count();
+ weak_this_ = shared_ptr<T>( *ppx, py );
}
- else if( !_shared_count.empty() )
+ else if( shared_this_.use_count() != 0 )
{
- BOOST_ASSERT( owner.unique() ); // no weak_ptrs to owner should exist either, but there's no way to check that
- detail::sp_deleter_wrapper * pd = detail::basic_get_deleter<detail::sp_deleter_wrapper>( _shared_count );
+ 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( owner.get_shared_count() );
- owner.reset( _shared_count, owner.get() );
- detail::shared_count().swap( _shared_count );
+ pd->set_deleter( *ppx );
+
+ ppx->reset( shared_this_, ppx->get() );
+ shared_this_.reset();
}
}
};
-template< class T, class Y > inline void sp_accept_owner( shared_ptr<Y> * ptr, enable_shared_from_this<T> const * pe )
-{
- if( pe != 0 )
- {
- pe->sp_accept_owner( *ptr );
- }
-}
-
-template< class T, class Y > inline void sp_accept_owner( shared_ptr<Y> * ptr, enable_shared_from_this<T> const * pe, void * /*pd*/ )
-{
- if( pe != 0 )
- {
- pe->sp_accept_owner( *ptr );
- }
-}
-
} // namespace boost
-#endif // #ifndef BOOST_ENABLE_SHARED_FROM_THIS_HPP_INCLUDED
+#endif // #ifndef BOOST_ENABLE_SHARED_FROM_THIS2_HPP_INCLUDED
Modified: branches/release/boost/smart_ptr/intrusive_ptr.hpp
==============================================================================
--- branches/release/boost/smart_ptr/intrusive_ptr.hpp (original)
+++ branches/release/boost/smart_ptr/intrusive_ptr.hpp 2009-08-08 19:21:15 EDT (Sat, 08 Aug 2009)
@@ -111,6 +111,23 @@
#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(std::move(rhs)).swap(*this);
+ return *this;
+ }
+
+#endif
+
intrusive_ptr & operator=(intrusive_ptr const & rhs)
{
this_type(rhs).swap(*this);
Modified: branches/release/boost/smart_ptr/shared_ptr.hpp
==============================================================================
--- branches/release/boost/smart_ptr/shared_ptr.hpp (original)
+++ branches/release/boost/smart_ptr/shared_ptr.hpp 2009-08-08 19:21:15 EDT (Sat, 08 Aug 2009)
@@ -61,6 +61,7 @@
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 +110,14 @@
}
}
+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
@@ -359,14 +368,14 @@
shared_ptr & operator=( shared_ptr && r ) // never throws
{
- this_type( static_cast< shared_ptr && >( r ) ).swap( *this );
+ this_type( std::move( r ) ).swap( *this );
return *this;
}
template<class Y>
shared_ptr & operator=( shared_ptr<Y> && r ) // never throws
{
- this_type( static_cast< shared_ptr<Y> && >( r ) ).swap( *this );
+ this_type( std::move( r ) ).swap( *this );
return *this;
}
Modified: branches/release/boost/smart_ptr/weak_ptr.hpp
==============================================================================
--- branches/release/boost/smart_ptr/weak_ptr.hpp (original)
+++ branches/release/boost/smart_ptr/weak_ptr.hpp 2009-08-08 19:21:15 EDT (Sat, 08 Aug 2009)
@@ -70,11 +70,43 @@
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( weak_ptr<Y> && r, typename detail::sp_enable_if_convertible<Y,T>::type = detail::sp_empty() )
+
+#else
+
+ weak_ptr( weak_ptr<Y> && r )
+
+#endif
+ : px(r.lock().get()), pn(std::move(r.pn)) // never throws
+ {
+ r.px = 0;
+ }
+
+ // for better efficiency in the T == Y case
+ weak_ptr( weak_ptr && r ): px( r.px ), pn(std::move(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( std::move( r ) ).swap( *this );
+ return *this;
+ }
+
+
+#endif
+
template<class Y>
#if !defined( BOOST_SP_NO_SP_CONVERTIBLE )
@@ -99,6 +131,17 @@
return *this;
}
+#if defined( BOOST_HAS_RVALUE_REFS )
+
+ template<class Y>
+ weak_ptr & operator=(weak_ptr<Y> && r)
+ {
+ this_type( std::move( r ) ).swap( *this );
+ return *this;
+ }
+
+#endif
+
template<class Y>
weak_ptr & operator=(shared_ptr<Y> const & r) // never throws
{
@@ -124,6 +167,11 @@
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);
Modified: branches/release/libs/smart_ptr/test/Jamfile.v2
==============================================================================
--- branches/release/libs/smart_ptr/test/Jamfile.v2 (original)
+++ branches/release/libs/smart_ptr/test/Jamfile.v2 2009-08-08 19:21:15 EDT (Sat, 08 Aug 2009)
@@ -16,9 +16,11 @@
[ 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 ]
@@ -56,6 +58,7 @@
[ 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 ]
;
Modified: branches/release/libs/smart_ptr/test/shared_ptr_move_test.cpp
==============================================================================
--- branches/release/libs/smart_ptr/test/shared_ptr_move_test.cpp (original)
+++ branches/release/libs/smart_ptr/test/shared_ptr_move_test.cpp 2009-08-08 19:21:15 EDT (Sat, 08 Aug 2009)
@@ -8,11 +8,11 @@
// http://www.boost.org/LICENSE_1_0.txt
//
-#if defined( BOOST_HAS_RVALUE_REFS )
-
#include <boost/shared_ptr.hpp>
#include <boost/detail/lightweight_test.hpp>
+#if defined( BOOST_HAS_RVALUE_REFS )
+
struct X
{
static long instances;
@@ -43,11 +43,11 @@
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 +60,12 @@
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 +79,13 @@
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 );
Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk