]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/leaf/test/BOOST_LEAF_CHECK_test.cpp
update ceph source to reef 18.1.2
[ceph.git] / ceph / src / boost / libs / leaf / test / BOOST_LEAF_CHECK_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/result.hpp>
10 # include <boost/leaf/handle_errors.hpp>
11 #endif
12
13 #ifdef BOOST_LEAF_BOOST_AVAILABLE
14 # include <boost/config/workaround.hpp>
15 #else
16 # define BOOST_WORKAROUND(a,b) 0
17 #endif
18
19 #include "lightweight_test.hpp"
20
21 namespace leaf = boost::leaf;
22
23 struct value
24 {
25 int x;
26
27 explicit value( int x ): x(x) { };
28
29 #ifndef BOOST_LEAF_NO_CXX11_REF_QUALIFIERS
30 value( value const & ) = delete;
31 value( value && ) = default;
32 #endif
33 };
34
35 leaf::result<value> f1( bool success )
36 {
37 if( success )
38 return value { 21 };
39 else
40 return leaf::new_error();
41 }
42
43 #if BOOST_LEAF_GNUC_STMTEXPR
44
45 leaf::result<value> f2( bool success )
46 {
47 return value { BOOST_LEAF_CHECK(f1(success)).x + BOOST_LEAF_CHECK(f1(success)).x };
48 }
49
50 #else
51
52 leaf::result<value> f2( bool success )
53 {
54 BOOST_LEAF_AUTO(a, f1(success));
55 BOOST_LEAF_AUTO(b, f1(success));
56 return value { a.x + b.x };
57 }
58
59 #endif
60
61 leaf::result<void> f3( bool success )
62 {
63 BOOST_LEAF_CHECK(f2(success));
64 return { };
65 }
66
67 int main()
68 {
69 BOOST_TEST_EQ(f2(true).value().x, 42);
70 BOOST_TEST(!f2(false));
71 BOOST_TEST(f3(true));
72 BOOST_TEST(!f3(false));
73
74 return boost::report_errors();
75 }