]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/leaf/test/BOOST_LEAF_AUTO_test.cpp
1 // Copyright 2018-2022 Emil Dotchevski and Reverge Studios, Inc.
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)
6 #ifdef BOOST_LEAF_TEST_SINGLE_HEADER
9 # include <boost/leaf/result.hpp>
10 # include <boost/leaf/handle_errors.hpp>
13 #include "lightweight_test.hpp"
14 #ifdef BOOST_LEAF_BOOST_AVAILABLE
15 # include <boost/config/workaround.hpp>
17 # define BOOST_WORKAROUND(a,b) 0
20 namespace leaf
= boost::leaf
;
26 explicit value( int x
): x(x
) { };
28 #ifndef BOOST_LEAF_NO_CXX11_REF_QUALIFIERS
29 value( value
const & ) = delete;
30 value( value
&& ) = default;
34 leaf::result
<value
> f1()
39 leaf::result
<value
> f2()
41 BOOST_LEAF_AUTO(a
, f1());
42 #if BOOST_WORKAROUND( BOOST_GCC, < 50000 ) || BOOST_WORKAROUND( BOOST_CLANG, <= 30800 )
43 return std::move(a
); // Older compilers are confused, but...
45 return a
; // ...this doesn't need to be return std::move(a);
49 template <class Lambda
>
50 leaf::result
<value
> f2_lambda( Lambda
)
52 BOOST_LEAF_AUTO(a
, f1());
53 #if BOOST_WORKAROUND( BOOST_GCC, < 50000 ) || BOOST_WORKAROUND( BOOST_CLANG, <= 30800 )
54 return std::move(a
); // Older compilers are confused, but...
56 return a
; // ...this doesn't need to be return std::move(a);
60 leaf::result
<value
> f3()
62 BOOST_LEAF_AUTO(a
, f2());
64 // Invoking the macro twice in the same scope, testing the temp name
65 // generation. Also making sure we can pass a lambda (See
66 // https://github.com/boostorg/leaf/issues/16).
67 BOOST_LEAF_AUTO(b
, f2_lambda([]{}));
69 return value
{ a
.x
+ b
.x
};
74 BOOST_TEST_EQ(f3()->x
, 42);
77 int r
= leaf::try_handle_all(
78 []() -> leaf::result
<int>
82 leaf::result
<int> r1(x
);
83 BOOST_LEAF_AUTO(rx1
, r1
);
84 BOOST_TEST_EQ(r1
.value(), rx1
);
86 leaf::result
<int &> r2(x
);
87 BOOST_LEAF_AUTO(rx2
, r2
);
88 BOOST_TEST_EQ(r2
.value(), rx2
);
99 return boost::report_errors();