|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r52937 - in trunk: boost/smart_ptr boost/smart_ptr/detail libs/smart_ptr/test
From: whatwasthataddress_at_[hidden]
Date: 2009-05-12 12:18:18
Author: tzlaine
Date: 2009-05-12 12:18:15 EDT (Tue, 12 May 2009)
New Revision: 52937
URL: http://svn.boost.org/trac/boost/changeset/52937
Log:
Merged in smart_ptr changes from the sandbox/boost0x branch created for
BoostCon '09. This adds move semantics to weak_ptr and intrusive_ptr.
Added:
trunk/libs/smart_ptr/test/intrusive_ptr_move_test.cpp
- copied unchanged from r52935, /sandbox/boost0x/libs/smart_ptr/test/intrusive_ptr_move_test.cpp
trunk/libs/smart_ptr/test/weak_ptr_move_test.cpp
- copied unchanged from r52935, /sandbox/boost0x/libs/smart_ptr/test/weak_ptr_move_test.cpp
Text files modified:
trunk/boost/smart_ptr/detail/shared_count.hpp | 14 +++++++++++
trunk/boost/smart_ptr/intrusive_ptr.hpp | 17 ++++++++++++++
trunk/boost/smart_ptr/shared_ptr.hpp | 4 +-
trunk/boost/smart_ptr/weak_ptr.hpp | 47 ++++++++++++++++++++++++++++++++++++++-
trunk/libs/smart_ptr/test/Jamfile.v2 | 2 +
trunk/libs/smart_ptr/test/shared_ptr_move_test.cpp | 16 ++++++------
6 files changed, 88 insertions(+), 12 deletions(-)
Modified: trunk/boost/smart_ptr/detail/shared_count.hpp
==============================================================================
--- trunk/boost/smart_ptr/detail/shared_count.hpp (original)
+++ trunk/boost/smart_ptr/detail/shared_count.hpp 2009-05-12 12:18:15 EDT (Tue, 12 May 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: trunk/boost/smart_ptr/intrusive_ptr.hpp
==============================================================================
--- trunk/boost/smart_ptr/intrusive_ptr.hpp (original)
+++ trunk/boost/smart_ptr/intrusive_ptr.hpp 2009-05-12 12:18:15 EDT (Tue, 12 May 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: trunk/boost/smart_ptr/shared_ptr.hpp
==============================================================================
--- trunk/boost/smart_ptr/shared_ptr.hpp (original)
+++ trunk/boost/smart_ptr/shared_ptr.hpp 2009-05-12 12:18:15 EDT (Tue, 12 May 2009)
@@ -368,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: trunk/boost/smart_ptr/weak_ptr.hpp
==============================================================================
--- trunk/boost/smart_ptr/weak_ptr.hpp (original)
+++ trunk/boost/smart_ptr/weak_ptr.hpp 2009-05-12 12:18:15 EDT (Tue, 12 May 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
{
Modified: trunk/libs/smart_ptr/test/Jamfile.v2
==============================================================================
--- trunk/libs/smart_ptr/test/Jamfile.v2 (original)
+++ trunk/libs/smart_ptr/test/Jamfile.v2 2009-05-12 12:18:15 EDT (Tue, 12 May 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 ]
Modified: trunk/libs/smart_ptr/test/shared_ptr_move_test.cpp
==============================================================================
--- trunk/libs/smart_ptr/test/shared_ptr_move_test.cpp (original)
+++ trunk/libs/smart_ptr/test/shared_ptr_move_test.cpp 2009-05-12 12:18:15 EDT (Tue, 12 May 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