mirror of
https://github.com/boostorg/interprocess.git
synced 2026-01-19 04:12:13 +00:00
Update intrusive_ptr move semantics to support Boost.Move.
This commit is contained in:
@@ -34,7 +34,6 @@
|
||||
#include <boost/container/detail/type_traits.hpp> //alignment_of, aligned_storage
|
||||
#include <boost/assert.hpp>
|
||||
#include <iosfwd>
|
||||
#include <iterator>
|
||||
|
||||
//!\file
|
||||
//!Describes a smart pointer that stores the offset between this pointer and
|
||||
|
||||
@@ -32,6 +32,7 @@
|
||||
#include <boost/interprocess/detail/utilities.hpp>
|
||||
#include <boost/intrusive/pointer_traits.hpp>
|
||||
#include <boost/move/adl_move_swap.hpp>
|
||||
#include <boost/move/core.hpp>
|
||||
|
||||
#include <iosfwd> // for std::basic_ostream
|
||||
|
||||
@@ -72,6 +73,8 @@ class intrusive_ptr
|
||||
typedef pointer this_type::*unspecified_bool_type;
|
||||
#endif //#ifndef BOOST_INTERPROCESS_DOXYGEN_INVOKED
|
||||
|
||||
BOOST_COPYABLE_AND_MOVABLE(intrusive_ptr)
|
||||
|
||||
public:
|
||||
//!Constructor. Initializes internal pointer to 0.
|
||||
//!Does not throw
|
||||
@@ -96,14 +99,12 @@ class intrusive_ptr
|
||||
if(m_ptr != 0) intrusive_ptr_add_ref(ipcdetail::to_raw_pointer(m_ptr));
|
||||
}
|
||||
|
||||
#ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
|
||||
//!Move constructor. Moves the internal pointer. Does not throw
|
||||
intrusive_ptr(intrusive_ptr&& rhs) BOOST_NOEXCEPT
|
||||
intrusive_ptr(BOOST_RV_REF(intrusive_ptr) rhs) BOOST_NOEXCEPT
|
||||
: m_ptr(rhs.m_ptr)
|
||||
{
|
||||
rhs.m_ptr = 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
//!Constructor from related. Copies the internal pointer and if "p" is not
|
||||
//!zero calls intrusive_ptr_add_ref(to_raw_pointer(p)). Does not throw
|
||||
@@ -121,23 +122,20 @@ class intrusive_ptr
|
||||
|
||||
//!Assignment operator. Equivalent to intrusive_ptr(r).swap(*this).
|
||||
//!Does not throw
|
||||
intrusive_ptr & operator=(intrusive_ptr const & rhs) BOOST_NOEXCEPT
|
||||
intrusive_ptr & operator=(BOOST_COPY_ASSIGN_REF(intrusive_ptr) rhs) BOOST_NOEXCEPT
|
||||
{
|
||||
this_type(rhs).swap(*this);
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
#ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
|
||||
//!Move Assignment operator
|
||||
//!Does not throw
|
||||
intrusive_ptr & operator=(intrusive_ptr&& rhs) BOOST_NOEXCEPT
|
||||
intrusive_ptr & operator=(BOOST_RV_REF(intrusive_ptr) rhs) BOOST_NOEXCEPT
|
||||
{
|
||||
rhs.swap(*this);
|
||||
rhs.reset();
|
||||
return *this;
|
||||
}
|
||||
#endif
|
||||
|
||||
//!Assignment from related. Equivalent to intrusive_ptr(r).swap(*this).
|
||||
//!Does not throw
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
#include <boost/core/lightweight_test.hpp>
|
||||
#include <boost/config.hpp>
|
||||
#include <boost/move/adl_move_swap.hpp>
|
||||
#include <boost/move/core.hpp>
|
||||
#include <functional>
|
||||
|
||||
typedef boost::interprocess::offset_ptr<void> VP;
|
||||
@@ -195,7 +196,6 @@ void copy_constructor()
|
||||
}
|
||||
}
|
||||
|
||||
#ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
|
||||
void move_constructor()
|
||||
{
|
||||
{
|
||||
@@ -204,26 +204,22 @@ void move_constructor()
|
||||
boost::interprocess::intrusive_ptr<X, VP> px(x);
|
||||
BOOST_TEST(addref_release_calls == prev_addref_release_calls + 1);
|
||||
|
||||
static_assert(std::is_nothrow_move_constructible< boost::interprocess::intrusive_ptr<X, VP> >::value, "test instrusive_ptr is nothrow move constructible");
|
||||
//static_assert(std::is_nothrow_move_constructible< boost::interprocess::intrusive_ptr<X, VP> >::value, "test instrusive_ptr is nothrow move constructible");
|
||||
|
||||
boost::interprocess::intrusive_ptr<X, VP> px2(std::move(px));
|
||||
boost::interprocess::intrusive_ptr<X, VP> px2(boost::move(px));
|
||||
BOOST_TEST(px2.get() == x);
|
||||
BOOST_TEST(px.get() == nullptr);
|
||||
BOOST_TEST(!px.get());
|
||||
BOOST_TEST(px2->use_count() == 1);
|
||||
BOOST_TEST(addref_release_calls == prev_addref_release_calls + 1);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
void test()
|
||||
{
|
||||
default_constructor();
|
||||
pointer_constructor();
|
||||
copy_constructor();
|
||||
|
||||
#ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
|
||||
move_constructor();
|
||||
#endif
|
||||
move_constructor();
|
||||
}
|
||||
|
||||
} // namespace n_constructors
|
||||
@@ -253,7 +249,6 @@ void copy_assignment()
|
||||
{
|
||||
}
|
||||
|
||||
#ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
|
||||
void move_assignment()
|
||||
{
|
||||
{
|
||||
@@ -263,17 +258,16 @@ void move_assignment()
|
||||
BOOST_TEST(px->use_count() == 1);
|
||||
BOOST_TEST(addref_release_calls == prev_addref_release_calls + 1);
|
||||
|
||||
static_assert(std::is_nothrow_move_assignable< boost::interprocess::intrusive_ptr<X, VP> >::value, "test if nothrow move assignable ");
|
||||
//static_assert(std::is_nothrow_move_assignable< boost::interprocess::intrusive_ptr<X, VP> >::value, "test if nothrow move assignable ");
|
||||
|
||||
boost::interprocess::intrusive_ptr<X, VP> px2;
|
||||
px2 = std::move(px);
|
||||
px2 = boost::move(px);
|
||||
BOOST_TEST(px2.get() == x);
|
||||
BOOST_TEST(px.get() == nullptr);
|
||||
BOOST_TEST(!px.get());
|
||||
BOOST_TEST(px2->use_count() == 1);
|
||||
BOOST_TEST(addref_release_calls == prev_addref_release_calls + 1);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
void conversion_assignment()
|
||||
{
|
||||
@@ -288,10 +282,7 @@ void test()
|
||||
copy_assignment();
|
||||
conversion_assignment();
|
||||
pointer_assignment();
|
||||
|
||||
#ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
|
||||
move_assignment();
|
||||
#endif
|
||||
}
|
||||
|
||||
} // namespace n_assignment
|
||||
|
||||
Reference in New Issue
Block a user