Merged in smart_ptr changes from the sandbox/boost0x branch created for

BoostCon '09.  This adds move semantics to weak_ptr and intrusive_ptr.


[SVN r52937]
This commit is contained in:
Timothy Zachary Laine committed 2009-05-12 16:18:15 +00:00
1 parent 4b4a62513f
commit fc12543814
8 files changed
+393 -12

No files matched your search

@@ -333,6 +333,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();
+17
View File
@@ -109,6 +109,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(std::move(rhs)).swap(*this);
return *this;
}
#endif
intrusive_ptr & operator=(intrusive_ptr const & rhs)
+2 -2
View File
@@ -368,14 +368,14 @@ public:
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;
}
+45 -2
View File
@@ -70,11 +70,43 @@ public:
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 @@ public:
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
{