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_inline.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 23 namespace ns 24 { 25 BOOST_FUSION_DEFINE_TPL_STRUCT_INLINE((W), value, (W, w)) 26 } 27 main()28int main() 29 { 30 using namespace boost::fusion; 31 32 { 33 ns::value<wrapper> x; 34 ns::value<wrapper> y(x); // copy 35 36 BOOST_TEST(x.w.value == 42); 37 BOOST_TEST(y.w.value == 42); 38 39 ++y.w.value; 40 41 BOOST_TEST(x.w.value == 42); 42 BOOST_TEST(y.w.value == 43); 43 44 y = x; // copy assign 45 46 BOOST_TEST(x.w.value == 42); 47 BOOST_TEST(y.w.value == 42); 48 } 49 50 // Older MSVCs and gcc 4.4 don't generate move ctor by default. 51 #if !(defined(CI_SKIP_KNOWN_FAILURE) && (BOOST_WORKAROUND(BOOST_MSVC, < 1900) || BOOST_WORKAROUND(BOOST_GCC, / 100 == 404))) 52 { 53 ns::value<wrapper> x; 54 ns::value<wrapper> y(std::move(x)); // move 55 56 BOOST_TEST(x.w.value == 0); 57 BOOST_TEST(y.w.value == 42); 58 59 ++y.w.value; 60 61 BOOST_TEST(x.w.value == 0); 62 BOOST_TEST(y.w.value == 43); 63 64 y = std::move(x); // move assign 65 66 BOOST_TEST(x.w.value == 0); 67 BOOST_TEST(y.w.value == 0); 68 } 69 #endif // !(ci && (msvc < 14.0 || gcc 4.4.x)) 70 71 return boost::report_errors(); 72 } 73 74