]> git.proxmox.com Git - ceph.git/blame - ceph/src/boost/libs/fusion/test/sequence/define_tpl_struct_move.cpp
update sources to ceph Nautilus 14.2.1
[ceph.git] / ceph / src / boost / libs / fusion / test / sequence / define_tpl_struct_move.cpp
CommitLineData
7c673cae 1/*=============================================================================
11fdf7f2 2 Copyright (c) 2016,2018 Kohei Takahashi
7c673cae
FG
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==============================================================================*/
7c673cae
FG
7#include <boost/detail/lightweight_test.hpp>
8#include <boost/fusion/adapted/struct/define_struct.hpp>
9#include <utility>
10
11struct wrapper
12{
13 int value;
14
15 wrapper() : value(42) {}
16 wrapper(wrapper&& other) : value(other.value) { other.value = 0; }
17 wrapper(wrapper const& other) : value(other.value) {}
18
19 wrapper& operator=(wrapper&& other) { value = other.value; other.value = 0; return *this; }
20 wrapper& operator=(wrapper const& other) { value = other.value; return *this; }
21};
22BOOST_FUSION_DEFINE_TPL_STRUCT((W), (ns), value, (W, w))
23
24int main()
25{
26 using namespace boost::fusion;
27
28 {
29 ns::value<wrapper> x;
30 ns::value<wrapper> 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<wrapper> x;
48 ns::value<wrapper> 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