]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/variant2/test/variant_in_place_index_construct_cx.cpp
2 // Copyright 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
9 #include <boost/variant2/variant.hpp>
10 #include <boost/config.hpp>
11 #include <boost/config/workaround.hpp>
13 using namespace boost::variant2
;
17 constexpr X() = default;
18 constexpr explicit X(int, int) {}
19 X( in_place_index_t
<0> ) = delete;
22 #define STATIC_ASSERT(...) static_assert(__VA_ARGS__, #__VA_ARGS__)
27 constexpr variant
<int> v( in_place_index_t
<0>{} );
29 STATIC_ASSERT( v
.index() == 0 );
30 STATIC_ASSERT( get
<0>(v
) == 0 );
34 constexpr variant
<X
> v( in_place_index_t
<0>{} );
36 STATIC_ASSERT( v
.index() == 0 );
40 constexpr variant
<int> v( in_place_index_t
<0>{}, 1 );
42 STATIC_ASSERT( v
.index() == 0 );
43 STATIC_ASSERT( get
<0>(v
) == 1 );
47 constexpr variant
<int, float> v( in_place_index_t
<0>{} );
49 STATIC_ASSERT( v
.index() == 0 );
50 STATIC_ASSERT( get
<0>(v
) == 0 );
54 constexpr variant
<int, float> v( in_place_index_t
<0>{}, 1 );
56 STATIC_ASSERT( v
.index() == 0 );
57 STATIC_ASSERT( get
<0>(v
) == 1 );
61 constexpr variant
<int, float> v( in_place_index_t
<1>{} );
63 STATIC_ASSERT( v
.index() == 1 );
64 STATIC_ASSERT( get
<1>(v
) == 0 );
68 constexpr variant
<int, float> v( in_place_index_t
<1>{}, 3.14f
);
70 STATIC_ASSERT( v
.index() == 1 );
71 STATIC_ASSERT( get
<1>(v
) == 3.14f
);
75 constexpr variant
<int, int, float, float, X
, X
> v( in_place_index_t
<0>{}, 1 );
77 STATIC_ASSERT( v
.index() == 0 );
78 STATIC_ASSERT( get
<0>(v
) == 1 );
82 constexpr variant
<int, int, float, float, X
, X
> v( in_place_index_t
<1>{}, 1 );
84 STATIC_ASSERT( v
.index() == 1 );
85 STATIC_ASSERT( get
<1>(v
) == 1 );
89 constexpr variant
<int, int, float, float, X
, X
> v( in_place_index_t
<2>{}, 3.14f
);
91 STATIC_ASSERT( v
.index() == 2 );
92 STATIC_ASSERT( get
<2>(v
) == 3.14f
);
96 constexpr variant
<int, int, float, float, X
, X
> v( in_place_index_t
<3>{}, 3.14f
);
98 STATIC_ASSERT( v
.index() == 3 );
99 STATIC_ASSERT( get
<3>(v
) == 3.14f
);
103 constexpr variant
<int, int, float, float, X
, X
> v( in_place_index_t
<4>{} );
105 STATIC_ASSERT( v
.index() == 4 );
108 #if BOOST_WORKAROUND(BOOST_GCC, >= 100000 && BOOST_GCC < 120000)
110 // no idea why this fails on g++ 10/11
115 constexpr variant
<int, int, float, float, X
, X
> v( in_place_index_t
<5>{}, 0, 0 );
117 STATIC_ASSERT( v
.index() == 5 );