]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/variant2/test/variant_copy_construct.cpp
import new upstream nautilus stable release 14.2.8
[ceph.git] / ceph / src / boost / libs / variant2 / test / variant_copy_construct.cpp
1
2 // Copyright 2017 Peter Dimov.
3 //
4 // Distributed under the Boost Software License, Version 1.0.
5 //
6 // See accompanying file LICENSE_1_0.txt or copy at
7 // http://www.boost.org/LICENSE_1_0.txt
8
9 #include <boost/variant2/variant.hpp>
10 #include <boost/core/lightweight_test.hpp>
11 #include <boost/core/lightweight_test_trait.hpp>
12 #include <type_traits>
13 #include <utility>
14 #include <string>
15
16 using namespace boost::variant2;
17
18 #define STATIC_ASSERT(...) static_assert(__VA_ARGS__, #__VA_ARGS__)
19
20 struct X1
21 {
22 X1() {}
23 X1(X1 const&) {}
24 X1(X1&&) {}
25 };
26
27 inline bool operator==( X1, X1 ) { return true; }
28
29 STATIC_ASSERT( !std::is_nothrow_default_constructible<X1>::value );
30 STATIC_ASSERT( !std::is_nothrow_copy_constructible<X1>::value );
31 STATIC_ASSERT( !std::is_nothrow_move_constructible<X1>::value );
32
33 struct X2
34 {
35 X2() {}
36 X2(X2 const&) {}
37 X2(X2&&) {}
38 };
39
40 inline bool operator==( X2, X2 ) { return true; }
41
42 STATIC_ASSERT( !std::is_nothrow_default_constructible<X2>::value );
43 STATIC_ASSERT( !std::is_nothrow_copy_constructible<X2>::value );
44 STATIC_ASSERT( !std::is_nothrow_move_constructible<X2>::value );
45
46 struct Y
47 {
48 Y( Y const& ) = delete;
49 };
50
51 template<class V> static void test( V const & v )
52 {
53 V v2( v );
54
55 BOOST_TEST_EQ( v.index(), v2.index() );
56 BOOST_TEST( v == v2 );
57 }
58
59 int main()
60 {
61 test( variant<int>() );
62 test( variant<int>(1) );
63
64 test( variant<int const>() );
65 test( variant<int const>(1) );
66
67 test( variant<int, float>() );
68 test( variant<int, float>(1) );
69 test( variant<int, float>(3.14f) );
70
71 test( variant<int const, float const>() );
72 test( variant<int const, float const>(1) );
73 test( variant<int const, float const>(3.14f) );
74
75 test( variant<std::string>() );
76 test( variant<std::string>("test") );
77
78 test( variant<std::string const>() );
79 test( variant<std::string const>("test") );
80
81 test( variant<int, float, std::string>() );
82 test( variant<int, float, std::string>(1) );
83 test( variant<int, float, std::string>(3.14f) );
84 test( variant<int, float, std::string>("test") );
85
86 test( variant<int, int>() );
87
88 test( variant<int, int, float>() );
89 test( variant<int, int, float>(3.14f) );
90
91 test( variant<int, int, float, float>() );
92
93 test( variant<int, int, float, float, std::string>("test") );
94
95 test( variant<std::string, std::string, float>() );
96
97 test( variant<X1 const>() );
98
99 test( variant<X1, X2>() );
100 test( variant<X1, X2, int>() );
101 test( variant<X1, X2, X2>() );
102 test( variant<X1, X1, X2, X2>() );
103
104 {
105 variant<X1, X2> v;
106 v.emplace<X2>();
107
108 test( v );
109 }
110
111 {
112 variant<X1, X1, X2> v;
113 v.emplace<X2>();
114
115 test( v );
116 }
117
118 {
119 BOOST_TEST_TRAIT_TRUE((std::is_nothrow_copy_constructible<variant<int>>));
120 BOOST_TEST_TRAIT_TRUE((std::is_nothrow_copy_constructible<variant<int const>>));
121 BOOST_TEST_TRAIT_TRUE((std::is_nothrow_copy_constructible<variant<int, int>>));
122 BOOST_TEST_TRAIT_TRUE((std::is_nothrow_copy_constructible<variant<int, float>>));
123 BOOST_TEST_TRAIT_TRUE((std::is_nothrow_copy_constructible<variant<int, int, float, float>>));
124
125 BOOST_TEST_TRAIT_FALSE((std::is_nothrow_copy_constructible<variant<X1>>));
126 BOOST_TEST_TRAIT_FALSE((std::is_nothrow_copy_constructible<variant<X1, int>>));
127 BOOST_TEST_TRAIT_FALSE((std::is_nothrow_copy_constructible<variant<X1, int, float>>));
128
129 BOOST_TEST_TRAIT_FALSE((std::is_nothrow_copy_constructible<variant<int, X1>>));
130 BOOST_TEST_TRAIT_FALSE((std::is_nothrow_copy_constructible<variant<int, int, X1>>));
131
132 BOOST_TEST_TRAIT_FALSE((std::is_nothrow_copy_constructible<variant<X1, X2>>));
133 BOOST_TEST_TRAIT_FALSE((std::is_nothrow_copy_constructible<variant<X1, X2, int, int>>));
134
135 BOOST_TEST_TRAIT_TRUE((std::is_copy_constructible<variant<X1, X2>>));
136
137 #if !BOOST_WORKAROUND( BOOST_MSVC, <= 1910 )
138
139 BOOST_TEST_TRAIT_FALSE((std::is_copy_constructible<variant<int, float, Y>>));
140
141 #endif
142 }
143
144 return boost::report_errors();
145 }