]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/mp11/test/construct_from_tuple_cx.cpp
import new upstream nautilus stable release 14.2.8
[ceph.git] / ceph / src / boost / libs / mp11 / test / construct_from_tuple_cx.cpp
1
2 // Copyright 2015 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 #if defined(_MSC_VER)
11 #pragma warning( disable: 4244 ) // 'initializing': conversion from 'int' to 'char', possible loss of data
12 #endif
13
14 #include <boost/mp11/tuple.hpp>
15 #include <boost/mp11/detail/config.hpp>
16
17 // Technically std::tuple isn't constexpr enabled in C++11, but it works with libstdc++
18
19 #if defined( BOOST_MP11_NO_CONSTEXPR ) || ( !defined( __GLIBCXX__ ) && __cplusplus < 201400L )
20
21 int main() {}
22
23 #else
24
25 #include <tuple>
26 #include <array>
27 #include <utility>
28
29 struct T1
30 {
31 int x, y, z;
32
33 constexpr T1( int x = 0, int y = 0, int z = 0 ): x(x), y(y), z(z) {}
34 };
35
36 int main()
37 {
38 using boost::mp11::construct_from_tuple;
39
40 {
41 constexpr std::tuple<int, short, char> tp{ 1, 2, 3 };
42
43 constexpr auto r = construct_from_tuple<T1>( tp );
44
45 static_assert( r.x == 1, "r.x == 1" );
46 static_assert( r.y == 2, "r.y == 2" );
47 static_assert( r.z == 3, "r.z == 3" );
48 }
49
50 {
51 constexpr std::pair<short, char> tp{ 1, 2 };
52
53 constexpr auto r = construct_from_tuple<T1>( tp );
54
55 static_assert( r.x == 1, "r.x == 1" );
56 static_assert( r.y == 2, "r.y == 2" );
57 static_assert( r.z == 0, "r.z == 0" );
58 }
59
60 {
61 constexpr std::array<short, 3> tp{{ 1, 2, 3 }};
62
63 constexpr auto r = construct_from_tuple<T1>( tp );
64
65 static_assert( r.x == 1, "r.x == 1" );
66 static_assert( r.y == 2, "r.y == 2" );
67 static_assert( r.z == 3, "r.z == 3" );
68 }
69
70 #if defined( __clang_major__ ) && __clang_major__ == 3 && __clang_minor__ < 9
71 // "error: default initialization of an object of const type 'const std::tuple<>' without a user-provided default constructor"
72 #else
73
74 {
75 constexpr std::tuple<> tp;
76
77 constexpr auto r = construct_from_tuple<T1>( tp );
78
79 static_assert( r.x == 0, "r.x == 0" );
80 static_assert( r.y == 0, "r.y == 0" );
81 static_assert( r.z == 0, "r.z == 0" );
82 }
83
84 #endif
85 }
86
87 #endif