]> git.proxmox.com Git - ceph.git/blame - ceph/src/boost/libs/variant2/test/variant_in_place_index_construct_cx.cpp
import quincy beta 17.1.0
[ceph.git] / ceph / src / boost / libs / variant2 / test / variant_in_place_index_construct_cx.cpp
CommitLineData
92f5a8d4
TL
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>
20effc67
TL
10#include <boost/config.hpp>
11#include <boost/config/workaround.hpp>
92f5a8d4
TL
12
13using namespace boost::variant2;
14
15struct X
16{
17 constexpr X() = default;
18 constexpr explicit X(int, int) {}
19 X( in_place_index_t<0> ) = delete;
20};
21
22#define STATIC_ASSERT(...) static_assert(__VA_ARGS__, #__VA_ARGS__)
23
24int main()
25{
26 {
27 constexpr variant<int> v( in_place_index_t<0>{} );
28
29 STATIC_ASSERT( v.index() == 0 );
30 STATIC_ASSERT( get<0>(v) == 0 );
31 }
32
33 {
34 constexpr variant<X> v( in_place_index_t<0>{} );
35
36 STATIC_ASSERT( v.index() == 0 );
37 }
38
39 {
40 constexpr variant<int> v( in_place_index_t<0>{}, 1 );
41
42 STATIC_ASSERT( v.index() == 0 );
43 STATIC_ASSERT( get<0>(v) == 1 );
44 }
45
46 {
47 constexpr variant<int, float> v( in_place_index_t<0>{} );
48
49 STATIC_ASSERT( v.index() == 0 );
50 STATIC_ASSERT( get<0>(v) == 0 );
51 }
52
53 {
54 constexpr variant<int, float> v( in_place_index_t<0>{}, 1 );
55
56 STATIC_ASSERT( v.index() == 0 );
57 STATIC_ASSERT( get<0>(v) == 1 );
58 }
59
60 {
61 constexpr variant<int, float> v( in_place_index_t<1>{} );
62
63 STATIC_ASSERT( v.index() == 1 );
64 STATIC_ASSERT( get<1>(v) == 0 );
65 }
66
67 {
68 constexpr variant<int, float> v( in_place_index_t<1>{}, 3.14f );
69
70 STATIC_ASSERT( v.index() == 1 );
71 STATIC_ASSERT( get<1>(v) == 3.14f );
72 }
73
74 {
75 constexpr variant<int, int, float, float, X, X> v( in_place_index_t<0>{}, 1 );
76
77 STATIC_ASSERT( v.index() == 0 );
78 STATIC_ASSERT( get<0>(v) == 1 );
79 }
80
81 {
82 constexpr variant<int, int, float, float, X, X> v( in_place_index_t<1>{}, 1 );
83
84 STATIC_ASSERT( v.index() == 1 );
85 STATIC_ASSERT( get<1>(v) == 1 );
86 }
87
88 {
89 constexpr variant<int, int, float, float, X, X> v( in_place_index_t<2>{}, 3.14f );
90
91 STATIC_ASSERT( v.index() == 2 );
92 STATIC_ASSERT( get<2>(v) == 3.14f );
93 }
94
95 {
96 constexpr variant<int, int, float, float, X, X> v( in_place_index_t<3>{}, 3.14f );
97
98 STATIC_ASSERT( v.index() == 3 );
99 STATIC_ASSERT( get<3>(v) == 3.14f );
100 }
101
102 {
103 constexpr variant<int, int, float, float, X, X> v( in_place_index_t<4>{} );
104
105 STATIC_ASSERT( v.index() == 4 );
106 }
107
20effc67
TL
108#if BOOST_WORKAROUND(BOOST_GCC, >= 100000 && BOOST_GCC < 100200)
109
110 // no idea why this fails on g++ 10
111
112#else
113
92f5a8d4
TL
114 {
115 constexpr variant<int, int, float, float, X, X> v( in_place_index_t<5>{}, 0, 0 );
116
117 STATIC_ASSERT( v.index() == 5 );
118 }
20effc67
TL
119
120#endif
92f5a8d4 121}