]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/leaf/test/to_variant_test.cpp
1 // Copyright 2018-2022 Emil Dotchevski and Reverge Studios, Inc.
3 // Distributed under the Boost Software License, Version 1.0. (See accompanying
4 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
6 #if __cplusplus < 201703L
12 std::cout
<< "Unit test not applicable." << std::endl
;
18 #ifdef BOOST_LEAF_TEST_SINGLE_HEADER
21 # include <boost/leaf/to_variant.hpp>
24 #include "_test_ec.hpp"
25 #include "lightweight_test.hpp"
27 namespace leaf
= boost::leaf
;
29 enum class E1
{ e11
, e12
, e13
};
30 enum class E2
{ e21
, e22
, e23
};
31 enum class E3
{ e31
, e32
, e33
};
35 #if !defined(__clang__) || __clang_major__ < 5 || __clang_major__ > 7 // See https://github.com/llvm/llvm-project/issues/32569
37 auto v
= leaf::to_variant
<E1
, E2
, E3
>(
38 [ ]() -> leaf::result
<int>
42 BOOST_TEST(v
.index() == 0);
43 BOOST_TEST(std::get
<0>(v
) == 42);
47 auto v
= leaf::to_variant
<E1
, E2
, E3
>(
48 [ ]() -> leaf::result
<int>
50 return leaf::new_error(E1::e12
, E3::e31
);
52 BOOST_TEST(v
.index() == 1);
53 auto t
= std::get
<1>(v
);
55 BOOST_TEST(std::get
<0>(t
).has_value());
56 BOOST_TEST(!std::get
<1>(t
).has_value());
57 BOOST_TEST(std::get
<2>(t
).has_value());
59 BOOST_TEST(std::get
<0>(t
).value() == E1::e12
);
60 BOOST_TEST(std::get
<2>(t
).value() == E3::e31
);
64 return boost::report_errors();