]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/leaf/test/preload_nested_error_result_test.cpp
import quincy beta 17.1.0
[ceph.git] / ceph / src / boost / libs / leaf / test / preload_nested_error_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 template <int>
14 struct info
15 {
16 int value;
17 };
18
19 leaf::error_id f0()
20 {
21 auto load = leaf::on_error(info<0>{});
22 return leaf::new_error( info<2>{2} );
23 }
24
25 leaf::error_id f1()
26 {
27 auto load = leaf::on_error( info<0>{-1}, info<1>{1}, info<2>{-1} );
28 return f0();
29 }
30
31 leaf::error_id f2()
32 {
33 return f1().load( info<3>{3} );
34 }
35
36 int main()
37 {
38 int r = leaf::try_handle_all(
39 []() -> leaf::result<int>
40 {
41 return f2();
42 },
43 []( info<0> i0, info<1> i1, info<2> i2, info<3> i3 )
44 {
45 BOOST_TEST_EQ(i0.value, 0);
46 BOOST_TEST_EQ(i1.value, 1);
47 BOOST_TEST_EQ(i2.value, 2);
48 BOOST_TEST_EQ(i3.value, 3);
49 return 1;
50 },
51 []
52 {
53 return 2;
54 } );
55 BOOST_TEST_EQ(r, 1);
56
57 return boost::report_errors();
58 }