]>
Commit | Line | Data |
---|---|---|
20effc67 TL |
1 | // Copyright (c) 2018-2020 Emil Dotchevski and Reverge Studios, Inc. |
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 | ||
6 | #include <boost/leaf/context.hpp> | |
7 | #include <boost/leaf/handle_errors.hpp> | |
8 | #include <boost/leaf/result.hpp> | |
9 | #include "lightweight_test.hpp" | |
10 | ||
11 | namespace leaf = boost::leaf; | |
12 | ||
13 | template <int> | |
14 | struct info | |
15 | { | |
16 | int value; | |
17 | }; | |
18 | ||
19 | template <class Ctx> | |
20 | leaf::result<int> f( Ctx & ctx ) | |
21 | { | |
22 | auto active_context = activate_context(ctx); | |
23 | return leaf::new_error( info<1>{1} ); | |
24 | } | |
25 | ||
26 | int main() | |
27 | { | |
28 | leaf::context<info<1>> ctx; | |
29 | ||
30 | { | |
31 | leaf::result<int> r1 = f(ctx); | |
32 | BOOST_TEST(!r1); | |
33 | ||
34 | leaf::result<int> r2 = ctx.handle_error<leaf::result<int>>( | |
35 | r1.error(), | |
36 | []( info<1> x ) -> leaf::result<int> | |
37 | { | |
38 | BOOST_TEST(x.value==1); | |
39 | return 1; | |
40 | }, | |
41 | [&r1] | |
42 | { | |
43 | return std::move(r1); | |
44 | } ); | |
45 | BOOST_TEST_EQ(r2.value(), 1); | |
46 | } | |
47 | ||
48 | return boost::report_errors(); | |
49 | } |