]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/leaf/test/match_value_test.cpp
1 // Copyright (c) 2018-2020 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 #include <boost/leaf/handle_errors.hpp>
7 #include <boost/leaf/pred.hpp>
8 #include <boost/leaf/result.hpp>
10 #include "_test_ec.hpp"
11 #include "lightweight_test.hpp"
13 namespace leaf
= boost::leaf
;
15 enum class my_error
{ e1
=1, e2
, e3
};
17 struct e_my_error
{ my_error value
; };
19 struct e_error_code
{ std::error_code value
; };
21 struct my_exception
: std::exception
26 template <class M
, class E
>
27 bool test(E
const & e
)
32 BOOST_TEST_EQ(&e
, &m
.matched
);
42 e_my_error e
= { my_error::e1
};
44 BOOST_TEST(( test
<leaf::match_value
<e_my_error
, my_error::e1
>>(e
) ));
45 BOOST_TEST(( !test
<leaf::match_value
<e_my_error
, my_error::e2
>>(e
) ));
46 BOOST_TEST(( test
<leaf::match_value
<e_my_error
, my_error::e2
, my_error::e1
>>(e
) ));
50 e_error_code e
= { errc_a::a0
};
52 BOOST_TEST(( test
<leaf::match_value
<leaf::condition
<e_error_code
, cond_x
>, cond_x::x00
>>(e
) ));
53 BOOST_TEST(( !test
<leaf::match_value
<leaf::condition
<e_error_code
, cond_x
>, cond_x::x11
>>(e
) ));
54 BOOST_TEST(( test
<leaf::match_value
<leaf::condition
<e_error_code
, cond_x
>, cond_x::x11
, cond_x::x00
>>(e
) ));
56 #if __cplusplus >= 201703L
57 BOOST_TEST(( test
<leaf::match_value
<e_error_code
, errc_a::a0
>>(e
) ));
58 BOOST_TEST(( !test
<leaf::match_value
<e_error_code
, errc_a::a2
>>(e
) ));
59 BOOST_TEST(( test
<leaf::match_value
<e_error_code
, errc_a::a2
, errc_a::a0
>>(e
) ));
64 int r
= leaf::try_handle_all(
65 []() -> leaf::result
<int>
67 return leaf::new_error(e_my_error
{my_error::e1
});
70 []( leaf::match_value
<e_my_error
, my_error::e1
> )
83 int r
= leaf::try_handle_all(
84 []() -> leaf::result
<int>
86 return leaf::new_error(e_my_error
{my_error::e1
});
89 []( leaf::match_value
<e_my_error
, my_error::e2
> )
101 return boost::report_errors();