Add intrusive_ptr converting move assignment.

This commit is contained in:
Peter Dimov
2016-05-17 18:43:41 +03:00
parent b7f99ceba6
commit e52905cf3c
2 changed files with 34 additions and 0 deletions

View File

@ -139,6 +139,13 @@ public:
rhs.px = 0;
}
template<class U>
intrusive_ptr & operator=(intrusive_ptr<U> && rhs) BOOST_NOEXCEPT
{
this_type( static_cast< intrusive_ptr<U> && >( rhs ) ).swap(*this);
return *this;
}
#endif
intrusive_ptr & operator=(intrusive_ptr const & rhs)

View File

@ -182,6 +182,33 @@ int main()
BOOST_TEST( N::base::instances == 0 );
}
{
boost::intrusive_ptr<Y> p( new Y );
BOOST_TEST( N::base::instances == 1 );
boost::intrusive_ptr<X> 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<Y> p( new Y );
BOOST_TEST( N::base::instances == 1 );
boost::intrusive_ptr<X> 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();
}