]> git.proxmox.com Git - ceph.git/blame - ceph/src/boost/libs/fusion/test/sequence/define_assoc_struct_move.cpp
update sources to ceph Nautilus 14.2.1
[ceph.git] / ceph / src / boost / libs / fusion / test / sequence / define_assoc_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_assoc_struct.hpp>
9#include <utility>
10
11struct key_type;
12struct wrapper
13{
14 int value;
15
16 wrapper() : value(42) {}
17 wrapper(wrapper&& other) : value(other.value) { other.value = 0; }
18 wrapper(wrapper const& other) : value(other.value) {}
19
20 wrapper& operator=(wrapper&& other) { value = other.value; other.value = 0; return *this; }
21 wrapper& operator=(wrapper const& other) { value = other.value; return *this; }
22};
23BOOST_FUSION_DEFINE_ASSOC_STRUCT((ns), value, (wrapper, w, key_type))
24
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