]> git.proxmox.com Git - ceph.git/blame - ceph/src/boost/libs/leaf/test/multiple_errors_test.cpp
update ceph source to reef 18.1.2
[ceph.git] / ceph / src / boost / libs / leaf / test / multiple_errors_test.cpp
CommitLineData
1e59de90 1// Copyright 2018-2022 Emil Dotchevski and Reverge Studios, Inc.
20effc67
TL
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
1e59de90 6#include <boost/leaf/config.hpp>
20effc67
TL
7#include <boost/leaf/handle_errors.hpp>
8
1e59de90
TL
9#ifdef BOOST_LEAF_TEST_SINGLE_HEADER
10# include "leaf.hpp"
11#else
12# include <boost/leaf/result.hpp>
13#endif
14
20effc67 15#include "lightweight_test.hpp"
1e59de90 16#include <exception>
20effc67
TL
17
18namespace leaf = boost::leaf;
19
20template <int A>
21struct info
22{
23 int value;
24};
25
26leaf::result<void> f12()
27{
28 return leaf::new_error( info<1>{1}, info<2>{2} );
29}
30
31leaf::result<void> f23()
32{
33 return leaf::new_error( info<2>{2}, info<3>{3} );
34}
35
36int main()
37{
38 {
39 int r = leaf::try_handle_all(
40 []() -> leaf::result<int>
41 {
42 leaf::result<void> r1 = f12();
43 (void) r1;
44 leaf::result<void> r2 = f23();
45 return r2.error();
46 },
47 []( info<1> )
48 {
49 return 1;
50 },
51 []( info<2> const & x, info<3> const & y )
52 {
53 BOOST_TEST_EQ(x.value, 2);
54 BOOST_TEST_EQ(y.value, 3);
55 return 2;
56 },
57 []
58 {
59 return 3;
60 } );
61 BOOST_TEST_EQ(r, 2);
62 }
63
64#ifndef BOOST_LEAF_NO_EXCEPTIONS
65 {
66 int r = leaf::try_catch(
67 []() -> int
68 {
69 try
70 {
71 throw leaf::exception(info<4>{4});
72 }
73 catch(...)
74 {
75 }
76 throw std::exception{};
77 },
78 []( std::exception const &, info<4> )
79 {
80 return 1;
81 },
82 []( std::exception const & )
83 {
84 return 2;
85 } );
86 BOOST_TEST_EQ(r, 2);
87 }
88#endif
89
90 return boost::report_errors();
91}