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