]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/leaf/test/defer_basic_test.cpp
bump version to 18.2.2-pve1
[ceph.git] / ceph / src / boost / libs / leaf / test / defer_basic_test.cpp
1 // Copyright 2018-2022 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 #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
14 #include "lightweight_test.hpp"
15 #include <sstream>
16
17 namespace leaf = boost::leaf;
18
19 int global;
20
21 int get_global() noexcept
22 {
23 return global;
24 }
25
26 template <int>
27 struct info
28 {
29 int value;
30 };
31
32 leaf::error_id g()
33 {
34 global = 0;
35 auto load = leaf::on_error( []{ return info<42>{get_global()}; }, []{ return info<-42>{-42}; } );
36 global = 42;
37 return leaf::new_error();
38 }
39
40 leaf::error_id f()
41 {
42 return g();
43 }
44
45 int main()
46 {
47 int r = leaf::try_handle_all(
48 []() -> leaf::result<int>
49 {
50 return f();
51 },
52 []( info<42> const & i42, leaf::diagnostic_info const & di )
53 {
54 BOOST_TEST_EQ(i42.value, 42);
55 #if BOOST_LEAF_CFG_STD_STRING
56 std::stringstream ss; ss << di;
57 std::string s = ss.str();
58 std::cout << s;
59 #if BOOST_LEAF_CFG_DIAGNOSTICS
60 BOOST_TEST(s.find("info<-42>")!=s.npos);
61 #else
62 BOOST_TEST(s.find("BOOST_LEAF_CFG_DIAGNOSTICS")!=s.npos);
63 #endif
64 #endif
65 return 1;
66 },
67 []
68 {
69 return 2;
70 } );
71 BOOST_TEST_EQ(r, 1);
72 return boost::report_errors();
73 }