]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/leaf/test/match_member_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/handle_errors.hpp>
22 # include <boost/leaf/pred.hpp>
23 # include <boost/leaf/result.hpp>
26 #include "_test_ec.hpp"
27 #include "lightweight_test.hpp"
30 namespace leaf
= boost::leaf
;
32 enum class my_error
{ e1
=1, e2
, e3
};
34 struct e_my_error
{ my_error value
; };
36 #if BOOST_LEAF_CFG_STD_SYSTEM_ERROR
37 struct e_error_code
{ std::error_code value
; };
40 struct my_exception
: std::exception
45 template <class M
, class E
>
46 bool test(E
const & e
)
51 BOOST_TEST_EQ(&e
, &m
.matched
);
61 e_my_error e
= { my_error::e1
};
63 BOOST_TEST(( test
<leaf::match_member
<&e_my_error::value
, my_error::e1
>>(e
) ));
64 BOOST_TEST(( !test
<leaf::match_member
<&e_my_error::value
, my_error::e2
>>(e
) ));
65 BOOST_TEST(( test
<leaf::match_member
<&e_my_error::value
, my_error::e2
, my_error::e1
>>(e
) ));
68 #if BOOST_LEAF_CFG_STD_SYSTEM_ERROR
70 e_error_code e
= { errc_a::a0
};
72 BOOST_TEST(( test
<leaf::match_member
<&e_error_code::value
, errc_a::a0
>>(e
) ));
73 BOOST_TEST(( !test
<leaf::match_member
<&e_error_code::value
, errc_a::a2
>>(e
) ));
74 BOOST_TEST(( test
<leaf::match_member
<&e_error_code::value
, errc_a::a2
, errc_a::a0
>>(e
) ));
79 int r
= leaf::try_handle_all(
80 []() -> leaf::result
<int>
82 return leaf::new_error(e_my_error
{my_error::e1
});
85 []( leaf::match_member
<&e_my_error::value
, my_error::e1
> )
98 int r
= leaf::try_handle_all(
99 []() -> leaf::result
<int>
101 return leaf::new_error(e_my_error
{my_error::e1
});
104 []( leaf::match_member
<&e_my_error::value
, my_error::e2
> )
116 return boost::report_errors();