]>
Commit | Line | Data |
---|---|---|
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 TL |
6 | #ifdef BOOST_LEAF_TEST_SINGLE_HEADER |
7 | # include "leaf.hpp" | |
8 | #else | |
9 | # include <boost/leaf/on_error.hpp> | |
10 | # include <boost/leaf/handle_errors.hpp> | |
11 | # include <boost/leaf/result.hpp> | |
12 | #endif | |
13 | ||
20effc67 TL |
14 | #include "lightweight_test.hpp" |
15 | ||
16 | namespace leaf = boost::leaf; | |
17 | ||
18 | template <int> | |
19 | struct info | |
20 | { | |
21 | int value; | |
22 | }; | |
23 | ||
24 | leaf::error_id g() | |
25 | { | |
26 | auto load = leaf::on_error( [](info<1> & x) {++x.value;} ); | |
27 | return leaf::new_error(); | |
28 | } | |
29 | ||
30 | leaf::error_id f() | |
31 | { | |
32 | auto load = leaf::on_error( [](info<1> & x) {++x.value;}, [](info<2> & x) {++x.value;} ); | |
33 | return g(); | |
34 | } | |
35 | ||
36 | int main() | |
37 | { | |
38 | int r = leaf::try_handle_all( | |
39 | []() -> leaf::result<int> | |
40 | { | |
41 | return f(); | |
42 | }, | |
43 | []( info<1> const & a, info<2> const & b ) | |
44 | { | |
45 | BOOST_TEST_EQ(a.value, 2); | |
46 | BOOST_TEST_EQ(b.value, 1); | |
47 | return 1; | |
48 | }, | |
49 | [] | |
50 | { | |
51 | return 2; | |
52 | } ); | |
53 | BOOST_TEST_EQ(r, 1); | |
54 | return boost::report_errors(); | |
55 | } |