]> git.proxmox.com Git - ceph.git/blame - ceph/src/boost/libs/fusion/test/sequence/define_struct_inline_move.cpp
update sources to v12.2.3
[ceph.git] / ceph / src / boost / libs / fusion / test / sequence / define_struct_inline_move.cpp
CommitLineData
7c673cae
FG
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_inline.hpp>
13#include <utility>
14
15struct 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
27namespace ns
28{
29 BOOST_FUSION_DEFINE_STRUCT_INLINE(value, (wrapper, w))
30}
31
32int main()
33{
34 using namespace boost::fusion;
35
36 {
37 ns::value x;
38 ns::value y(x); // copy
39
40 BOOST_TEST(x.w.value == 42);
41 BOOST_TEST(y.w.value == 42);
42
43 ++y.w.value;
44
45 BOOST_TEST(x.w.value == 42);
46 BOOST_TEST(y.w.value == 43);
47
48 y = x; // copy assign
49
50 BOOST_TEST(x.w.value == 42);
51 BOOST_TEST(y.w.value == 42);
52 }
53
b32b8144
FG
54 // Older MSVCs don't generate move ctor by default.
55#if !(defined(RUNNING_ON_APPVEYOR) && BOOST_WORKAROUND(BOOST_MSVC, < 1900))
7c673cae
FG
56 {
57 ns::value x;
58 ns::value y(std::move(x)); // move
59
60 BOOST_TEST(x.w.value == 0);
61 BOOST_TEST(y.w.value == 42);
62
63 ++y.w.value;
64
65 BOOST_TEST(x.w.value == 0);
66 BOOST_TEST(y.w.value == 43);
67
68 y = std::move(x); // move assign
69
70 BOOST_TEST(x.w.value == 0);
71 BOOST_TEST(y.w.value == 0);
72 }
b32b8144 73#endif // !(appveyor && msvc < 14.0)
7c673cae
FG
74
75 return boost::report_errors();
76}
77
78#else
79
80int main()
81{
82}
83
84#endif