]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/fusion/test/sequence/define_struct_move.cpp
add subtree-ish sources for 12.0.3
[ceph.git] / ceph / src / boost / libs / fusion / test / sequence / define_struct_move.cpp
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_struct.hpp>
13 #include <utility>
14
15 struct wrapper
16 {
17 int value;
18
19 wrapper() : value(42) {}
20 wrapper(wrapper&& other) : value(other.value) { other.value = 0; }
21 wrapper(wrapper const& other) : value(other.value) {}
22
23 wrapper& operator=(wrapper&& other) { value = other.value; other.value = 0; return *this; }
24 wrapper& operator=(wrapper const& other) { value = other.value; return *this; }
25 };
26 BOOST_FUSION_DEFINE_STRUCT((ns), value, (wrapper, w))
27
28 int main()
29 {
30 using namespace boost::fusion;
31
32 {
33 ns::value x;
34 ns::value 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 {
51 ns::value x;
52 ns::value y(std::move(x)); // move
53
54 BOOST_TEST(x.w.value == 0);
55 BOOST_TEST(y.w.value == 42);
56
57 ++y.w.value;
58
59 BOOST_TEST(x.w.value == 0);
60 BOOST_TEST(y.w.value == 43);
61
62 y = std::move(x); // move assign
63
64 BOOST_TEST(x.w.value == 0);
65 BOOST_TEST(y.w.value == 0);
66 }
67
68 return boost::report_errors();
69 }
70
71 #else
72
73 int main()
74 {
75 }
76
77 #endif