]> git.proxmox.com Git - ceph.git/blame - ceph/src/boost/libs/leaf/test/accumulate_basic_test.cpp
update ceph source to reef 18.1.2
[ceph.git] / ceph / src / boost / libs / leaf / test / accumulate_basic_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 g()
25{
26 auto load = leaf::on_error( [](info<1> & x) {++x.value;} );
27 return leaf::new_error();
28}
29
30leaf::error_id f()
31{
32 auto load = leaf::on_error( [](info<1> & x) {++x.value;}, [](info<2> & x) {++x.value;} );
33 return g();
34}
35
36int main()
37{
38 int r = leaf::try_handle_all(
39 []() -> leaf::result<int>
40 {
41 return f();
42 },
43 []( info<1> const & a, info<2> const & b )
44 {
45 BOOST_TEST_EQ(a.value, 2);
46 BOOST_TEST_EQ(b.value, 1);
47 return 1;
48 },
49 []
50 {
51 return 2;
52 } );
53 BOOST_TEST_EQ(r, 1);
54 return boost::report_errors();
55}