]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/leaf/test/preload_nested_success_result_test.cpp
import quincy beta 17.1.0
[ceph.git] / ceph / src / boost / libs / leaf / test / preload_nested_success_result_test.cpp
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/on_error.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 struct info { int value; };
14
15 leaf::result<void> g1()
16 {
17 auto load = leaf::on_error( info{1} );
18 return { };
19 }
20
21 leaf::result<void> g2()
22 {
23 return leaf::new_error();
24 }
25
26 leaf::result<void> f()
27 {
28 auto load = leaf::on_error( info{2} );
29 BOOST_LEAF_CHECK(g1());
30 return g2();
31 }
32
33 int main()
34 {
35 int r = leaf::try_handle_all(
36 []() -> leaf::result<int>
37 {
38 BOOST_LEAF_CHECK(f());
39 return 1;
40 },
41 []( info x )
42 {
43 BOOST_TEST_EQ(x.value, 2);
44 return 2;
45 },
46 []
47 {
48 return 3;
49 } );
50 BOOST_TEST_EQ(r, 2);
51
52 return boost::report_errors();
53 }