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