1 /*============================================================================= 2 Copyright (c) 2016,2018 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 #include <boost/detail/lightweight_test.hpp> 8 #include <boost/fusion/adapted/struct/define_struct.hpp> 9 #include <utility> 10 11 struct wrapper 12 { 13 int value; 14 wrapperwrapper15 wrapper() : value(42) {} wrapperwrapper16 wrapper(wrapper&& other) : value(other.value) { other.value = 0; } wrapperwrapper17 wrapper(wrapper const& other) : value(other.value) {} 18 operator =wrapper19 wrapper& operator=(wrapper&& other) { value = other.value; other.value = 0; return *this; } operator =wrapper20 wrapper& operator=(wrapper const& other) { value = other.value; return *this; } 21 }; 22 BOOST_FUSION_DEFINE_STRUCT((ns), value, (wrapper, w)) 23 main()24int main() 25 { 26 using namespace boost::fusion; 27 28 { 29 ns::value x; 30 ns::value y(x); // copy 31 32 BOOST_TEST(x.w.value == 42); 33 BOOST_TEST(y.w.value == 42); 34 35 ++y.w.value; 36 37 BOOST_TEST(x.w.value == 42); 38 BOOST_TEST(y.w.value == 43); 39 40 y = x; // copy assign 41 42 BOOST_TEST(x.w.value == 42); 43 BOOST_TEST(y.w.value == 42); 44 } 45 46 { 47 ns::value x; 48 ns::value y(std::move(x)); // move 49 50 BOOST_TEST(x.w.value == 0); 51 BOOST_TEST(y.w.value == 42); 52 53 ++y.w.value; 54 55 BOOST_TEST(x.w.value == 0); 56 BOOST_TEST(y.w.value == 43); 57 58 y = std::move(x); // move assign 59 60 BOOST_TEST(x.w.value == 0); 61 BOOST_TEST(y.w.value == 0); 62 } 63 64 return boost::report_errors(); 65 } 66 67