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