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