Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r81730 - in trunk: boost/smart_ptr libs/smart_ptr/test
From: pdimov_at_[hidden]
Date: 2012-12-05 22:18:55


Author: pdimov
Date: 2012-12-05 22:18:54 EST (Wed, 05 Dec 2012)
New Revision: 81730
URL: http://svn.boost.org/trac/boost/changeset/81730

Log:
Fix get_pointer for the array case, add operator= for unique_ptr, update auto_ptr signatures to use rvalue reference when available.
Text files modified:
   trunk/boost/smart_ptr/shared_ptr.hpp | 45 ++++++++++++++++++++++++++++++++++-----
   trunk/libs/smart_ptr/test/sp_unique_ptr_test.cpp | 24 +++++++++++++++++++++
   2 files changed, 63 insertions(+), 6 deletions(-)

Modified: trunk/boost/smart_ptr/shared_ptr.hpp
==============================================================================
--- trunk/boost/smart_ptr/shared_ptr.hpp (original)
+++ trunk/boost/smart_ptr/shared_ptr.hpp 2012-12-05 22:18:54 EST (Wed, 05 Dec 2012)
@@ -418,17 +418,30 @@
 #ifndef BOOST_NO_AUTO_PTR
 
     template<class Y>
- explicit shared_ptr(std::auto_ptr<Y> & r): px(r.get()), pn()
+ explicit shared_ptr( std::auto_ptr<Y> & r ): px(r.get()), pn()
     {
         boost::detail::sp_assert_convertible< Y, T >();
 
         Y * tmp = r.get();
- pn = boost::detail::shared_count(r);
+ pn = boost::detail::shared_count( r );
 
         boost::detail::sp_deleter_construct( this, tmp );
     }
 
-#if !defined( BOOST_NO_SFINAE ) && !defined( BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION )
+#if defined( BOOST_HAS_RVALUE_REFS )
+
+ template<class Y>
+ shared_ptr( std::auto_ptr<Y> && r ): px(r.get()), pn()
+ {
+ boost::detail::sp_assert_convertible< Y, T >();
+
+ Y * tmp = r.get();
+ pn = boost::detail::shared_count( r );
+
+ boost::detail::sp_deleter_construct( this, tmp );
+ }
+
+#elif !defined( BOOST_NO_SFINAE ) && !defined( BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION )
 
     template<class Ap>
     explicit shared_ptr( Ap r, typename boost::detail::sp_enable_if_auto_ptr<Ap, int>::type = 0 ): px( r.get() ), pn()
@@ -486,11 +499,20 @@
     template<class Y>
     shared_ptr & operator=( std::auto_ptr<Y> & r )
     {
- this_type(r).swap(*this);
+ this_type( r ).swap( *this );
         return *this;
     }
 
-#if !defined( BOOST_NO_SFINAE ) && !defined( BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION )
+#if defined( BOOST_HAS_RVALUE_REFS )
+
+ template<class Y>
+ shared_ptr & operator=( std::auto_ptr<Y> && r )
+ {
+ this_type( static_cast< std::auto_ptr<Y> && >( r ) ).swap( *this );
+ return *this;
+ }
+
+#elif !defined( BOOST_NO_SFINAE ) && !defined( BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION )
 
     template<class Ap>
     typename boost::detail::sp_enable_if_auto_ptr< Ap, shared_ptr & >::type operator=( Ap r )
@@ -503,6 +525,17 @@
 
 #endif // BOOST_NO_AUTO_PTR
 
+#if !defined( BOOST_NO_CXX11_SMART_PTR )
+
+ template<class Y, class D>
+ shared_ptr & operator=( std::unique_ptr<Y, D> && r )
+ {
+ this_type( static_cast< std::unique_ptr<Y, D> && >( r ) ).swap(*this);
+ return *this;
+ }
+
+#endif
+
 // Move support
 
 #if defined( BOOST_HAS_RVALUE_REFS )
@@ -730,7 +763,7 @@
 
 // get_pointer() enables boost::mem_fn to recognize shared_ptr
 
-template<class T> inline T * get_pointer(shared_ptr<T> const & p) BOOST_NOEXCEPT
+template<class T> inline typename shared_ptr<T>::element_type * get_pointer(shared_ptr<T> const & p) BOOST_NOEXCEPT
 {
     return p.get();
 }

Modified: trunk/libs/smart_ptr/test/sp_unique_ptr_test.cpp
==============================================================================
--- trunk/libs/smart_ptr/test/sp_unique_ptr_test.cpp (original)
+++ trunk/libs/smart_ptr/test/sp_unique_ptr_test.cpp 2012-12-05 22:18:54 EST (Wed, 05 Dec 2012)
@@ -91,6 +91,12 @@
         p2.reset();
         p3.reset();
         BOOST_TEST( X::instances == 0 );
+
+ p2 = std::unique_ptr<X>( new X );
+ BOOST_TEST( X::instances == 1 );
+
+ p2.reset();
+ BOOST_TEST( X::instances == 0 );
     }
 
     {
@@ -105,6 +111,12 @@
 
         p2.reset();
         BOOST_TEST( Y::instances == 0 );
+
+ p2 = std::unique_ptr<Y, YD>( new Y, YD() );
+ BOOST_TEST( Y::instances == 1 );
+
+ p2.reset();
+ BOOST_TEST( Y::instances == 0 );
     }
 
     {
@@ -121,6 +133,12 @@
 
         p2.reset();
         BOOST_TEST( Y::instances == 0 );
+
+ p2 = std::unique_ptr<Y, YD&>( new Y, yd );
+ BOOST_TEST( Y::instances == 1 );
+
+ p2.reset();
+ BOOST_TEST( Y::instances == 0 );
     }
 
     {
@@ -137,6 +155,12 @@
 
         p2.reset();
         BOOST_TEST( Y::instances == 0 );
+
+ p2 = std::unique_ptr<Y, YD const&>( new Y, yd );
+ BOOST_TEST( Y::instances == 1 );
+
+ p2.reset();
+ BOOST_TEST( Y::instances == 0 );
     }
 
     return boost::report_errors();


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