]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/leaf/test/to_variant_test.cpp
update ceph source to reef 18.1.2
[ceph.git] / ceph / src / boost / libs / leaf / test / to_variant_test.cpp
1 // Copyright 2018-2022 Emil Dotchevski and Reverge Studios, Inc.
2
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)
5
6 #if __cplusplus < 201703L
7
8 #include <iostream>
9
10 int main()
11 {
12 std::cout << "Unit test not applicable." << std::endl;
13 return 0;
14 }
15
16 #else
17
18 #ifdef BOOST_LEAF_TEST_SINGLE_HEADER
19 # include "leaf.hpp"
20 #else
21 # include <boost/leaf/to_variant.hpp>
22 #endif
23
24 #include "_test_ec.hpp"
25 #include "lightweight_test.hpp"
26
27 namespace leaf = boost::leaf;
28
29 enum class E1 { e11, e12, e13 };
30 enum class E2 { e21, e22, e23 };
31 enum class E3 { e31, e32, e33 };
32
33 int main()
34 {
35 #if !defined(__clang__) || __clang_major__ < 5 || __clang_major__ > 7 // See https://github.com/llvm/llvm-project/issues/32569
36 {
37 auto v = leaf::to_variant<E1, E2, E3>(
38 [ ]() -> leaf::result<int>
39 {
40 return 42;
41 } );
42 BOOST_TEST(v.index() == 0);
43 BOOST_TEST(std::get<0>(v) == 42);
44 }
45
46 {
47 auto v = leaf::to_variant<E1, E2, E3>(
48 [ ]() -> leaf::result<int>
49 {
50 return leaf::new_error(E1::e12, E3::e31);
51 } );
52 BOOST_TEST(v.index() == 1);
53 auto t = std::get<1>(v);
54
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());
58
59 BOOST_TEST(std::get<0>(t).value() == E1::e12);
60 BOOST_TEST(std::get<2>(t).value() == E3::e31);
61 }
62 #endif
63
64 return boost::report_errors();
65 }
66
67 #endif