]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/variant2/test/variant_emplace_index_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>
11 using namespace boost::variant2
;
17 constexpr explicit X( int v
): v( v
) {}
18 constexpr operator int() const { return v
; }
25 constexpr explicit Y( int v
): v( v
) {}
26 constexpr operator int() const { return v
; }
29 #define STATIC_ASSERT(...) static_assert(__VA_ARGS__, #__VA_ARGS__)
31 template<class V
, std::size_t I
, class A
> constexpr A
test( A
const& a
)
35 v
.template emplace
<I
>( a
);
43 constexpr auto w
= test
<variant
<int>, 0>( 1 );
44 STATIC_ASSERT( w
== 1 );
48 constexpr auto w
= test
<variant
<X
>, 0>( 1 );
49 STATIC_ASSERT( w
== 1 );
52 #if defined( BOOST_LIBSTDCXX_VERSION ) && BOOST_LIBSTDCXX_VERSION < 50000
56 constexpr auto w
= test
<variant
<Y
>, 0>( 1 );
57 STATIC_ASSERT( w
== 1 );
63 constexpr auto w
= test
<variant
<int, float>, 0>( 1 );
64 STATIC_ASSERT( w
== 1 );
68 constexpr auto w
= test
<variant
<int, float>, 1>( 3.0f
);
69 STATIC_ASSERT( w
== 3.0f
);
73 constexpr auto w
= test
<variant
<int, int, float, float, X
, X
>, 0>( 1 );
74 STATIC_ASSERT( w
== 1 );
78 constexpr auto w
= test
<variant
<int, int, float, float, X
, X
>, 1>( 1 );
79 STATIC_ASSERT( w
== 1 );
83 constexpr auto w
= test
<variant
<int, int, float, float, X
, X
>, 2>( 2.0f
);
84 STATIC_ASSERT( w
== 2.0f
);
88 constexpr auto w
= test
<variant
<int, int, float, float, X
, X
>, 3>( 3.0f
);
89 STATIC_ASSERT( w
== 3.0f
);
93 constexpr auto w
= test
<variant
<int, int, float, float, X
, X
>, 4>( 4 );
94 STATIC_ASSERT( w
== 4 );
98 constexpr auto w
= test
<variant
<int, int, float, float, X
, X
>, 5>( 5 );
99 STATIC_ASSERT( w
== 5 );
102 #if defined( BOOST_LIBSTDCXX_VERSION ) && BOOST_LIBSTDCXX_VERSION < 50000
106 constexpr auto w
= test
<variant
<int, int, float, float, Y
, Y
>, 0>( 1 );
107 STATIC_ASSERT( w
== 1 );
111 constexpr auto w
= test
<variant
<int, int, float, float, Y
, Y
>, 1>( 1 );
112 STATIC_ASSERT( w
== 1 );
116 constexpr auto w
= test
<variant
<int, int, float, float, Y
, Y
>, 2>( 2.0f
);
117 STATIC_ASSERT( w
== 2.0f
);
121 constexpr auto w
= test
<variant
<int, int, float, float, Y
, Y
>, 3>( 3.0f
);
122 STATIC_ASSERT( w
== 3.0f
);
126 constexpr auto w
= test
<variant
<int, int, float, float, Y
, Y
>, 4>( 4 );
127 STATIC_ASSERT( w
== 4 );
131 constexpr auto w
= test
<variant
<int, int, float, float, Y
, Y
>, 5>( 5 );
132 STATIC_ASSERT( w
== 5 );