]> git.proxmox.com Git - ceph.git/blame - ceph/src/boost/libs/leaf/test/defer_nested_error_exception_test.cpp
update ceph source to reef 18.1.2
[ceph.git] / ceph / src / boost / libs / leaf / test / defer_nested_error_exception_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#include <boost/leaf/config.hpp>
7
20effc67
TL
8#ifdef BOOST_LEAF_NO_EXCEPTIONS
9
10#include <iostream>
11
12int main()
13{
14 std::cout << "Unit test not applicable." << std::endl;
15 return 0;
16}
17
18#else
19
1e59de90
TL
20#ifdef BOOST_LEAF_TEST_SINGLE_HEADER
21# include "leaf.hpp"
22#else
23# include <boost/leaf/on_error.hpp>
24# include <boost/leaf/handle_errors.hpp>
25# include <boost/leaf/exception.hpp>
26#endif
27
20effc67
TL
28#include "lightweight_test.hpp"
29
30namespace leaf = boost::leaf;
31
32template <int>
33struct info
34{
35 int value;
36};
37
38void f0()
39{
40 auto load = leaf::on_error( [] { return info<0>{0}; } );
41 throw leaf::exception(info<2>{2});
42}
43
44void f1()
45{
46 auto load = leaf::on_error( [] { return info<0>{-1}; }, [] { return info<1>{1}; }, [] { return info<2>{-1}; } );
47 f0();
48}
49
50void f2()
51{
52 try
53 {
54 f1();
55 }
56 catch( leaf::error_id const & err )
57 {
58 err.load( info<3>{3} );
59 throw;
60 }
61}
62
63int main()
64{
65 int r = leaf::try_catch(
66 []
67 {
68 f2();
69 return 0;
70 },
71 []( info<0> i0, info<1> i1, info<2> i2, info<3> i3 )
72 {
73 BOOST_TEST_EQ(i0.value, 0);
74 BOOST_TEST_EQ(i1.value, 1);
75 BOOST_TEST_EQ(i2.value, 2);
76 BOOST_TEST_EQ(i3.value, 3);
77 return 1;
78 },
79 []
80 {
81 return 2;
82 } );
83 BOOST_TEST_EQ(r, 1);
84
85 return boost::report_errors();
86}
87
88#endif