#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;
+namespace {
+ int addref_release_calls = 0;
+}
+
namespace N
{
void add_ref()
{
+ ++addref_release_calls;
++use_count_;
}
void release()
{
+ ++addref_release_calls;
if(--use_count_ == 0) delete this;
}
};
}
}
+void move_constructor()
+{
+ {
+ int prev_addref_release_calls = addref_release_calls;
+ X* x = new X();
+ 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");
+
+ boost::interprocess::intrusive_ptr<X, VP> px2(boost::move(px));
+ BOOST_TEST(px2.get() == x);
+ BOOST_TEST(!px.get());
+ BOOST_TEST(px2->use_count() == 1);
+ BOOST_TEST(addref_release_calls == prev_addref_release_calls + 1);
+ }
+}
+
void test()
{
default_constructor();
pointer_constructor();
copy_constructor();
+ move_constructor();
}
} // namespace n_constructors
{
}
+void move_assignment()
+{
+ {
+ int prev_addref_release_calls = addref_release_calls;
+ X* x = new X();
+ boost::interprocess::intrusive_ptr<X, VP> px(x);
+ 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 ");
+
+ boost::interprocess::intrusive_ptr<X, VP> px2;
+ px2 = boost::move(px);
+ BOOST_TEST(px2.get() == x);
+ BOOST_TEST(!px.get());
+ BOOST_TEST(px2->use_count() == 1);
+ BOOST_TEST(addref_release_calls == prev_addref_release_calls + 1);
+ }
+}
+
void conversion_assignment()
{
}
copy_assignment();
conversion_assignment();
pointer_assignment();
+ move_assignment();
}
} // namespace n_assignment