diff --git a/include/boost/smart_ptr/shared_ptr.hpp b/include/boost/smart_ptr/shared_ptr.hpp index 5e13c01..6a09c28 100644 --- a/include/boost/smart_ptr/shared_ptr.hpp +++ b/include/boost/smart_ptr/shared_ptr.hpp @@ -418,17 +418,30 @@ public: #ifndef BOOST_NO_AUTO_PTR template - explicit shared_ptr(std::auto_ptr & r): px(r.get()), pn() + explicit shared_ptr( std::auto_ptr & 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 + shared_ptr( std::auto_ptr && 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 explicit shared_ptr( Ap r, typename boost::detail::sp_enable_if_auto_ptr::type = 0 ): px( r.get() ), pn() @@ -486,11 +499,20 @@ public: template shared_ptr & operator=( std::auto_ptr & 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 + shared_ptr & operator=( std::auto_ptr && r ) + { + this_type( static_cast< std::auto_ptr && >( r ) ).swap( *this ); + return *this; + } + +#elif !defined( BOOST_NO_SFINAE ) && !defined( BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION ) template typename boost::detail::sp_enable_if_auto_ptr< Ap, shared_ptr & >::type operator=( Ap r ) @@ -503,6 +525,17 @@ public: #endif // BOOST_NO_AUTO_PTR +#if !defined( BOOST_NO_CXX11_SMART_PTR ) + + template + shared_ptr & operator=( std::unique_ptr && r ) + { + this_type( static_cast< std::unique_ptr && >( r ) ).swap(*this); + return *this; + } + +#endif + // Move support #if defined( BOOST_HAS_RVALUE_REFS ) @@ -730,7 +763,7 @@ template shared_ptr reinterpret_pointer_cast( shared_ptr // get_pointer() enables boost::mem_fn to recognize shared_ptr -template inline T * get_pointer(shared_ptr const & p) BOOST_NOEXCEPT +template inline typename shared_ptr::element_type * get_pointer(shared_ptr const & p) BOOST_NOEXCEPT { return p.get(); } diff --git a/test/sp_unique_ptr_test.cpp b/test/sp_unique_ptr_test.cpp index 70c5aff..7656e75 100644 --- a/test/sp_unique_ptr_test.cpp +++ b/test/sp_unique_ptr_test.cpp @@ -91,6 +91,12 @@ int main() p2.reset(); p3.reset(); BOOST_TEST( X::instances == 0 ); + + p2 = std::unique_ptr( new X ); + BOOST_TEST( X::instances == 1 ); + + p2.reset(); + BOOST_TEST( X::instances == 0 ); } { @@ -105,6 +111,12 @@ int main() p2.reset(); BOOST_TEST( Y::instances == 0 ); + + p2 = std::unique_ptr( new Y, YD() ); + BOOST_TEST( Y::instances == 1 ); + + p2.reset(); + BOOST_TEST( Y::instances == 0 ); } { @@ -121,6 +133,12 @@ int main() p2.reset(); BOOST_TEST( Y::instances == 0 ); + + p2 = std::unique_ptr( new Y, yd ); + BOOST_TEST( Y::instances == 1 ); + + p2.reset(); + BOOST_TEST( Y::instances == 0 ); } { @@ -137,6 +155,12 @@ int main() p2.reset(); BOOST_TEST( Y::instances == 0 ); + + p2 = std::unique_ptr( new Y, yd ); + BOOST_TEST( Y::instances == 1 ); + + p2.reset(); + BOOST_TEST( Y::instances == 0 ); } return boost::report_errors();