]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/mp11/test/construct_from_tuple.cpp
update sources to v12.2.3
[ceph.git] / ceph / src / boost / libs / mp11 / test / construct_from_tuple.cpp
1
2 // Copyright 2015, 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
10 #include <boost/mp11/tuple.hpp>
11 #include <boost/core/lightweight_test.hpp>
12 #include <boost/config.hpp>
13 #include <boost/detail/workaround.hpp>
14 #include <tuple>
15 #include <memory>
16 #include <utility>
17 #include <array>
18
19 struct T1
20 {
21 int x, y, z;
22
23 T1( int x = 0, int y = 0, int z = 0 ): x(x), y(y), z(z) {}
24 };
25
26 struct T2
27 {
28 std::unique_ptr<int> x, y, z;
29
30 T2( std::unique_ptr<int> x, std::unique_ptr<int> y, std::unique_ptr<int> z ): x(std::move(x)), y(std::move(y)), z(std::move(z)) {}
31
32 #if BOOST_WORKAROUND( BOOST_MSVC, <= 1800 )
33
34 T2( T2&& r ): x( std::move(r.x) ), y( std::move(r.y) ), z( std::move(r.z) ) {}
35
36 #endif
37 };
38
39 int main()
40 {
41 using boost::mp11::construct_from_tuple;
42
43 {
44 std::tuple<int, short, char> tp{ 1, 2, 3 };
45
46 {
47 T1 t1 = construct_from_tuple<T1>( tp );
48
49 BOOST_TEST_EQ( t1.x, 1 );
50 BOOST_TEST_EQ( t1.y, 2 );
51 BOOST_TEST_EQ( t1.z, 3 );
52 }
53
54 {
55 T1 t1 = construct_from_tuple<T1>( std::move(tp) );
56
57 BOOST_TEST_EQ( t1.x, 1 );
58 BOOST_TEST_EQ( t1.y, 2 );
59 BOOST_TEST_EQ( t1.z, 3 );
60 }
61 }
62
63 {
64 std::tuple<int, short, char> const tp{ 1, 2, 3 };
65
66 {
67 T1 t1 = construct_from_tuple<T1>( tp );
68
69 BOOST_TEST_EQ( t1.x, 1 );
70 BOOST_TEST_EQ( t1.y, 2 );
71 BOOST_TEST_EQ( t1.z, 3 );
72 }
73
74 {
75 T1 t1 = construct_from_tuple<T1>( std::move(tp) );
76
77 BOOST_TEST_EQ( t1.x, 1 );
78 BOOST_TEST_EQ( t1.y, 2 );
79 BOOST_TEST_EQ( t1.z, 3 );
80 }
81 }
82
83 #if defined( __clang_major__ ) && __clang_major__ == 3 && __clang_minor__ < 8
84 #else
85
86 {
87 std::tuple<std::unique_ptr<int>, std::unique_ptr<int>, std::unique_ptr<int>> tp{ std::unique_ptr<int>(new int(1)), std::unique_ptr<int>(new int(2)), std::unique_ptr<int>(new int(3)) };
88
89 T2 t2 = construct_from_tuple<T2>( std::move(tp) );
90
91 BOOST_TEST_EQ( *t2.x, 1 );
92 BOOST_TEST_EQ( *t2.y, 2 );
93 BOOST_TEST_EQ( *t2.z, 3 );
94 }
95
96 #endif
97
98 {
99 std::pair<int, short> tp{ 1, 2 };
100
101 {
102 T1 t1 = construct_from_tuple<T1>( tp );
103
104 BOOST_TEST_EQ( t1.x, 1 );
105 BOOST_TEST_EQ( t1.y, 2 );
106 BOOST_TEST_EQ( t1.z, 0 );
107 }
108
109 {
110 T1 t1 = construct_from_tuple<T1>( std::move(tp) );
111
112 BOOST_TEST_EQ( t1.x, 1 );
113 BOOST_TEST_EQ( t1.y, 2 );
114 BOOST_TEST_EQ( t1.z, 0 );
115 }
116 }
117
118 {
119 std::pair<int, short> const tp{ 1, 2 };
120
121 {
122 T1 t1 = construct_from_tuple<T1>( tp );
123
124 BOOST_TEST_EQ( t1.x, 1 );
125 BOOST_TEST_EQ( t1.y, 2 );
126 BOOST_TEST_EQ( t1.z, 0 );
127 }
128
129 {
130 T1 t1 = construct_from_tuple<T1>( std::move(tp) );
131
132 BOOST_TEST_EQ( t1.x, 1 );
133 BOOST_TEST_EQ( t1.y, 2 );
134 BOOST_TEST_EQ( t1.z, 0 );
135 }
136 }
137
138 {
139 std::array<int, 3> tp{{ 1, 2, 3 }};
140
141 {
142 T1 t1 = construct_from_tuple<T1>( tp );
143
144 BOOST_TEST_EQ( t1.x, 1 );
145 BOOST_TEST_EQ( t1.y, 2 );
146 BOOST_TEST_EQ( t1.z, 3 );
147 }
148
149 {
150 T1 t1 = construct_from_tuple<T1>( std::move(tp) );
151
152 BOOST_TEST_EQ( t1.x, 1 );
153 BOOST_TEST_EQ( t1.y, 2 );
154 BOOST_TEST_EQ( t1.z, 3 );
155 }
156 }
157
158 {
159 std::array<int, 3> const tp{{ 1, 2, 3 }};
160
161 {
162 T1 t1 = construct_from_tuple<T1>( tp );
163
164 BOOST_TEST_EQ( t1.x, 1 );
165 BOOST_TEST_EQ( t1.y, 2 );
166 BOOST_TEST_EQ( t1.z, 3 );
167 }
168
169 {
170 T1 t1 = construct_from_tuple<T1>( std::move(tp) );
171
172 BOOST_TEST_EQ( t1.x, 1 );
173 BOOST_TEST_EQ( t1.y, 2 );
174 BOOST_TEST_EQ( t1.z, 3 );
175 }
176 }
177
178 {
179 std::tuple<> tp;
180
181 {
182 T1 t1 = construct_from_tuple<T1>( tp );
183
184 BOOST_TEST_EQ( t1.x, 0 );
185 BOOST_TEST_EQ( t1.y, 0 );
186 BOOST_TEST_EQ( t1.z, 0 );
187 }
188
189 {
190 T1 t1 = construct_from_tuple<T1>( std::move(tp) );
191
192 BOOST_TEST_EQ( t1.x, 0 );
193 BOOST_TEST_EQ( t1.y, 0 );
194 BOOST_TEST_EQ( t1.z, 0 );
195 }
196 }
197
198 {
199 std::array<int, 0> tp;
200
201 {
202 T1 t1 = construct_from_tuple<T1>( tp );
203
204 BOOST_TEST_EQ( t1.x, 0 );
205 BOOST_TEST_EQ( t1.y, 0 );
206 BOOST_TEST_EQ( t1.z, 0 );
207 }
208
209 {
210 T1 t1 = construct_from_tuple<T1>( std::move(tp) );
211
212 BOOST_TEST_EQ( t1.x, 0 );
213 BOOST_TEST_EQ( t1.y, 0 );
214 BOOST_TEST_EQ( t1.z, 0 );
215 }
216 }
217
218 return boost::report_errors();
219 }