]>
Commit | Line | Data |
---|---|---|
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_inline.hpp> | |
9 | #include <utility> | |
10 | ||
11 | struct 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 | }; | |
22 | ||
23 | namespace ns | |
24 | { | |
25 | BOOST_FUSION_DEFINE_TPL_STRUCT_INLINE((W), value, (W, w)) | |
26 | } | |
27 | ||
28 | int 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 | ||
92f5a8d4 TL |
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))) | |
7c673cae FG |
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 | } | |
92f5a8d4 | 69 | #endif // !(ci && (msvc < 14.0 || gcc 4.4.x)) |
7c673cae FG |
70 | |
71 | return boost::report_errors(); | |
72 | } | |
73 |