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