1 /*============================================================================= 2 Copyright (c) 2016 Kohei Takahashi 3 4 Distributed under the Boost Software License, Version 1.0. (See accompanying 5 file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 6 ==============================================================================*/ 7 8 #include <boost/config.hpp> 9 #ifndef BOOST_NO_CXX11_RVALUE_REFERENCES 10 11 #include <boost/detail/lightweight_test.hpp> 12 #include <boost/fusion/adapted/struct/define_assoc_struct.hpp> 13 #include <utility> 14 15 struct key_type; 16 struct wrapper 17 { 18 int value; 19 wrapperwrapper20 wrapper() : value(42) {} wrapperwrapper21 wrapper(wrapper&& other) : value(other.value) { other.value = 0; } wrapperwrapper22 wrapper(wrapper const& other) : value(other.value) {} 23 operator =wrapper24 wrapper& operator=(wrapper&& other) { value = other.value; other.value = 0; return *this; } operator =wrapper25 wrapper& operator=(wrapper const& other) { value = other.value; return *this; } 26 }; 27 BOOST_FUSION_DEFINE_ASSOC_TPL_STRUCT((W), (ns), value, (W, w, key_type)) 28 main()29int main() 30 { 31 using namespace boost::fusion; 32 33 { 34 ns::value<wrapper> x; 35 ns::value<wrapper> y(x); // copy 36 37 BOOST_TEST(x.w.value == 42); 38 BOOST_TEST(y.w.value == 42); 39 40 ++y.w.value; 41 42 BOOST_TEST(x.w.value == 42); 43 BOOST_TEST(y.w.value == 43); 44 45 y = x; // copy assign 46 47 BOOST_TEST(x.w.value == 42); 48 BOOST_TEST(y.w.value == 42); 49 } 50 51 { 52 ns::value<wrapper> x; 53 ns::value<wrapper> y(std::move(x)); // move 54 55 BOOST_TEST(x.w.value == 0); 56 BOOST_TEST(y.w.value == 42); 57 58 ++y.w.value; 59 60 BOOST_TEST(x.w.value == 0); 61 BOOST_TEST(y.w.value == 43); 62 63 y = std::move(x); // move assign 64 65 BOOST_TEST(x.w.value == 0); 66 BOOST_TEST(y.w.value == 0); 67 } 68 69 return boost::report_errors(); 70 } 71 72 #else 73 main()74int main() 75 { 76 } 77 78 #endif 79