]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/leaf/test/defer_basic_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/on_error.hpp>
10 # include <boost/leaf/handle_errors.hpp>
11 # include <boost/leaf/result.hpp>
14 #include "lightweight_test.hpp"
17 namespace leaf
= boost::leaf
;
21 int get_global() noexcept
35 auto load
= leaf::on_error( []{ return info
<42>{get_global()}; }, []{ return info
<-42>{-42}; } );
37 return leaf::new_error();
47 int r
= leaf::try_handle_all(
48 []() -> leaf::result
<int>
52 []( info
<42> const & i42
, leaf::diagnostic_info
const & di
)
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();
59 #if BOOST_LEAF_CFG_DIAGNOSTICS
60 BOOST_TEST(s
.find("info<-42>")!=s
.npos
);
62 BOOST_TEST(s
.find("BOOST_LEAF_CFG_DIAGNOSTICS")!=s
.npos
);
72 return boost::report_errors();