]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/leaf/test/match_member_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 #if __cplusplus < 201703L
12 std::cout
<< "Unit test not applicable." << std::endl
;
18 #include <boost/leaf/handle_errors.hpp>
19 #include <boost/leaf/pred.hpp>
20 #include <boost/leaf/result.hpp>
22 #include "_test_ec.hpp"
23 #include "lightweight_test.hpp"
25 namespace leaf
= boost::leaf
;
27 enum class my_error
{ e1
=1, e2
, e3
};
29 struct e_my_error
{ my_error value
; };
31 struct e_error_code
{ std::error_code value
; };
33 struct my_exception
: std::exception
38 template <class M
, class E
>
39 bool test(E
const & e
)
44 BOOST_TEST_EQ(&e
, &m
.matched
);
54 e_my_error e
= { my_error::e1
};
56 BOOST_TEST(( test
<leaf::match_member
<&e_my_error::value
, my_error::e1
>>(e
) ));
57 BOOST_TEST(( !test
<leaf::match_member
<&e_my_error::value
, my_error::e2
>>(e
) ));
58 BOOST_TEST(( test
<leaf::match_member
<&e_my_error::value
, my_error::e2
, my_error::e1
>>(e
) ));
62 e_error_code e
= { errc_a::a0
};
64 BOOST_TEST(( test
<leaf::match_member
<&e_error_code::value
, errc_a::a0
>>(e
) ));
65 BOOST_TEST(( !test
<leaf::match_member
<&e_error_code::value
, errc_a::a2
>>(e
) ));
66 BOOST_TEST(( test
<leaf::match_member
<&e_error_code::value
, errc_a::a2
, errc_a::a0
>>(e
) ));
70 int r
= leaf::try_handle_all(
71 []() -> leaf::result
<int>
73 return leaf::new_error(e_my_error
{my_error::e1
});
76 []( leaf::match_member
<&e_my_error::value
, my_error::e1
> )
89 int r
= leaf::try_handle_all(
90 []() -> leaf::result
<int>
92 return leaf::new_error(e_my_error
{my_error::e1
});
95 []( leaf::match_member
<&e_my_error::value
, my_error::e2
> )
107 return boost::report_errors();