From e52905cf3c264ee454ca5978d7986bfd58bcb573 Mon Sep 17 00:00:00 2001 From: Peter Dimov Date: Tue, 17 May 2016 18:43:41 +0300 Subject: [PATCH] Add intrusive_ptr converting move assignment. --- include/boost/smart_ptr/intrusive_ptr.hpp | 7 ++++++ test/intrusive_ptr_move_test.cpp | 27 +++++++++++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/include/boost/smart_ptr/intrusive_ptr.hpp b/include/boost/smart_ptr/intrusive_ptr.hpp index dceb817..1e93397 100644 --- a/include/boost/smart_ptr/intrusive_ptr.hpp +++ b/include/boost/smart_ptr/intrusive_ptr.hpp @@ -139,6 +139,13 @@ public: rhs.px = 0; } + template + intrusive_ptr & operator=(intrusive_ptr && rhs) BOOST_NOEXCEPT + { + this_type( static_cast< intrusive_ptr && >( rhs ) ).swap(*this); + return *this; + } + #endif intrusive_ptr & operator=(intrusive_ptr const & rhs) diff --git a/test/intrusive_ptr_move_test.cpp b/test/intrusive_ptr_move_test.cpp index c97bd11..2f2f652 100644 --- a/test/intrusive_ptr_move_test.cpp +++ b/test/intrusive_ptr_move_test.cpp @@ -182,6 +182,33 @@ int main() BOOST_TEST( N::base::instances == 0 ); } + { + boost::intrusive_ptr p( new Y ); + BOOST_TEST( N::base::instances == 1 ); + + boost::intrusive_ptr p2; + p2 = std::move( p ); + BOOST_TEST( N::base::instances == 1 ); + BOOST_TEST( p.get() == 0 ); + + p2.reset(); + BOOST_TEST( N::base::instances == 0 ); + } + + { + boost::intrusive_ptr p( new Y ); + BOOST_TEST( N::base::instances == 1 ); + + boost::intrusive_ptr p2( new X ); + BOOST_TEST( N::base::instances == 2 ); + p2 = std::move( p ); + BOOST_TEST( N::base::instances == 1 ); + BOOST_TEST( p.get() == 0 ); + + p2.reset(); + BOOST_TEST( N::base::instances == 0 ); + } + return boost::report_errors(); }