]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/mp11/test/construct_from_tuple.cpp
b4b7f34da473511efd906e92490d54990910238f
2 // Copyright 2015, 2017 Peter Dimov.
4 // Distributed under the Boost Software License, Version 1.0.
6 // See accompanying file LICENSE_1_0.txt or copy at
7 // http://www.boost.org/LICENSE_1_0.txt
11 #pragma warning( disable: 4244 ) // 'initializing': conversion from 'int' to 'char', possible loss of data
14 #include <boost/mp11/tuple.hpp>
15 #include <boost/mp11/detail/config.hpp>
16 #include <boost/core/lightweight_test.hpp>
26 T1( int x
= 0, int y
= 0, int z
= 0 ): x(x
), y(y
), z(z
) {}
31 std::unique_ptr
<int> x
, y
, z
;
33 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 #if BOOST_MP11_WORKAROUND( BOOST_MP11_MSVC, <= 1800 )
37 T2( T2
&& r
): x( std::move(r
.x
) ), y( std::move(r
.y
) ), z( std::move(r
.z
) ) {}
44 using boost::mp11::construct_from_tuple
;
47 std::tuple
<int, short, char> tp
{ 1, 2, 3 };
50 T1 t1
= construct_from_tuple
<T1
>( tp
);
52 BOOST_TEST_EQ( t1
.x
, 1 );
53 BOOST_TEST_EQ( t1
.y
, 2 );
54 BOOST_TEST_EQ( t1
.z
, 3 );
58 T1 t1
= construct_from_tuple
<T1
>( std::move(tp
) );
60 BOOST_TEST_EQ( t1
.x
, 1 );
61 BOOST_TEST_EQ( t1
.y
, 2 );
62 BOOST_TEST_EQ( t1
.z
, 3 );
67 std::tuple
<int, short, char> const tp
{ 1, 2, 3 };
70 T1 t1
= construct_from_tuple
<T1
>( tp
);
72 BOOST_TEST_EQ( t1
.x
, 1 );
73 BOOST_TEST_EQ( t1
.y
, 2 );
74 BOOST_TEST_EQ( t1
.z
, 3 );
78 T1 t1
= construct_from_tuple
<T1
>( std::move(tp
) );
80 BOOST_TEST_EQ( t1
.x
, 1 );
81 BOOST_TEST_EQ( t1
.y
, 2 );
82 BOOST_TEST_EQ( t1
.z
, 3 );
86 #if defined( __clang_major__ ) && __clang_major__ == 3 && __clang_minor__ < 8
90 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 T2 t2
= construct_from_tuple
<T2
>( std::move(tp
) );
94 BOOST_TEST_EQ( *t2
.x
, 1 );
95 BOOST_TEST_EQ( *t2
.y
, 2 );
96 BOOST_TEST_EQ( *t2
.z
, 3 );
102 std::pair
<int, short> tp
{ 1, 2 };
105 T1 t1
= construct_from_tuple
<T1
>( tp
);
107 BOOST_TEST_EQ( t1
.x
, 1 );
108 BOOST_TEST_EQ( t1
.y
, 2 );
109 BOOST_TEST_EQ( t1
.z
, 0 );
113 T1 t1
= construct_from_tuple
<T1
>( std::move(tp
) );
115 BOOST_TEST_EQ( t1
.x
, 1 );
116 BOOST_TEST_EQ( t1
.y
, 2 );
117 BOOST_TEST_EQ( t1
.z
, 0 );
122 std::pair
<int, short> const tp
{ 1, 2 };
125 T1 t1
= construct_from_tuple
<T1
>( tp
);
127 BOOST_TEST_EQ( t1
.x
, 1 );
128 BOOST_TEST_EQ( t1
.y
, 2 );
129 BOOST_TEST_EQ( t1
.z
, 0 );
133 T1 t1
= construct_from_tuple
<T1
>( std::move(tp
) );
135 BOOST_TEST_EQ( t1
.x
, 1 );
136 BOOST_TEST_EQ( t1
.y
, 2 );
137 BOOST_TEST_EQ( t1
.z
, 0 );
142 std::array
<int, 3> tp
{{ 1, 2, 3 }};
145 T1 t1
= construct_from_tuple
<T1
>( tp
);
147 BOOST_TEST_EQ( t1
.x
, 1 );
148 BOOST_TEST_EQ( t1
.y
, 2 );
149 BOOST_TEST_EQ( t1
.z
, 3 );
153 T1 t1
= construct_from_tuple
<T1
>( std::move(tp
) );
155 BOOST_TEST_EQ( t1
.x
, 1 );
156 BOOST_TEST_EQ( t1
.y
, 2 );
157 BOOST_TEST_EQ( t1
.z
, 3 );
162 std::array
<int, 3> const tp
{{ 1, 2, 3 }};
165 T1 t1
= construct_from_tuple
<T1
>( tp
);
167 BOOST_TEST_EQ( t1
.x
, 1 );
168 BOOST_TEST_EQ( t1
.y
, 2 );
169 BOOST_TEST_EQ( t1
.z
, 3 );
173 T1 t1
= construct_from_tuple
<T1
>( std::move(tp
) );
175 BOOST_TEST_EQ( t1
.x
, 1 );
176 BOOST_TEST_EQ( t1
.y
, 2 );
177 BOOST_TEST_EQ( t1
.z
, 3 );
185 T1 t1
= construct_from_tuple
<T1
>( tp
);
187 BOOST_TEST_EQ( t1
.x
, 0 );
188 BOOST_TEST_EQ( t1
.y
, 0 );
189 BOOST_TEST_EQ( t1
.z
, 0 );
193 T1 t1
= construct_from_tuple
<T1
>( std::move(tp
) );
195 BOOST_TEST_EQ( t1
.x
, 0 );
196 BOOST_TEST_EQ( t1
.y
, 0 );
197 BOOST_TEST_EQ( t1
.z
, 0 );
202 std::array
<int, 0> tp
;
205 T1 t1
= construct_from_tuple
<T1
>( tp
);
207 BOOST_TEST_EQ( t1
.x
, 0 );
208 BOOST_TEST_EQ( t1
.y
, 0 );
209 BOOST_TEST_EQ( t1
.z
, 0 );
213 T1 t1
= construct_from_tuple
<T1
>( std::move(tp
) );
215 BOOST_TEST_EQ( t1
.x
, 0 );
216 BOOST_TEST_EQ( t1
.y
, 0 );
217 BOOST_TEST_EQ( t1
.z
, 0 );
221 return boost::report_errors();