]> git.proxmox.com Git - ceph.git/blame - ceph/src/boost/libs/leaf/test/BOOST_LEAF_ASSIGN_test.cpp
update ceph source to reef 18.1.2
[ceph.git] / ceph / src / boost / libs / leaf / test / BOOST_LEAF_ASSIGN_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/result.hpp>
10# include <boost/leaf/handle_errors.hpp>
11#endif
12
20effc67 13#include "lightweight_test.hpp"
1e59de90
TL
14#ifdef BOOST_LEAF_BOOST_AVAILABLE
15# include <boost/config/workaround.hpp>
16#else
17# define BOOST_WORKAROUND(a,b) 0
18#endif
20effc67
TL
19
20namespace leaf = boost::leaf;
21
22struct value
23{
24 int x;
25
26 explicit value( int x ): x(x) { };
1e59de90
TL
27
28#ifndef BOOST_LEAF_NO_CXX11_REF_QUALIFIERS
20effc67
TL
29 value( value const & ) = delete;
30 value( value && ) = default;
1e59de90 31#endif
20effc67
TL
32};
33
34leaf::result<value> f1()
35{
36 return value { 21 };
37}
38
39leaf::result<value> f2()
40{
41 BOOST_LEAF_ASSIGN(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...
44#else
45 return a; // ...this doesn't need to be return std::move(a);
46#endif
47}
48
49leaf::result<value> f3()
50{
51 BOOST_LEAF_ASSIGN(auto a, f2());
52 BOOST_LEAF_ASSIGN(auto b, f2()); // Invoking the macro twice in the same scope, testing the temp name generation
53 return value { a.x + b.x };
54}
55
56int main()
57{
58 BOOST_TEST_EQ(f3()->x, 42);
59
60 {
61 int r = leaf::try_handle_all(
62 []() -> leaf::result<int>
63 {
64 int x = 42;
65
66 leaf::result<int> r1(x);
67 BOOST_LEAF_ASSIGN(auto && rx1, r1);
68 BOOST_TEST_EQ(r1.value(), rx1);
69
70 leaf::result<int &> r2(x);
71 BOOST_LEAF_ASSIGN(auto && rx2, r2);
72 BOOST_TEST_EQ(r2.value(), rx2);
73
74 leaf::result<int &> r3(x);
75 BOOST_LEAF_ASSIGN(auto & rx3, r3);
76 BOOST_TEST_EQ(&r3.value(), &rx3);
77
78 return 0;
79 },
80 []
81 {
82 return 1;
83 } );
84 BOOST_TEST_EQ(r, 0);
85 }
86
87 return boost::report_errors();
88}