]> git.proxmox.com Git - ceph.git/blame - ceph/src/boost/libs/leaf/test/ctx_handle_some_test.cpp
import quincy beta 17.1.0
[ceph.git] / ceph / src / boost / libs / leaf / test / ctx_handle_some_test.cpp
CommitLineData
20effc67
TL
1// Copyright (c) 2018-2020 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#include <boost/leaf/context.hpp>
7#include <boost/leaf/handle_errors.hpp>
8#include <boost/leaf/result.hpp>
9#include "lightweight_test.hpp"
10
11namespace leaf = boost::leaf;
12
13template <int>
14struct info
15{
16 int value;
17};
18
19template <class Ctx>
20leaf::result<int> f( Ctx & ctx )
21{
22 auto active_context = activate_context(ctx);
23 return leaf::new_error( info<1>{1} );
24}
25
26int main()
27{
28 leaf::context<info<1>> ctx;
29
30 {
31 leaf::result<int> r1 = f(ctx);
32 BOOST_TEST(!r1);
33
34 leaf::result<int> r2 = ctx.handle_error<leaf::result<int>>(
35 r1.error(),
36 []( info<1> x ) -> leaf::result<int>
37 {
38 BOOST_TEST(x.value==1);
39 return 1;
40 },
41 [&r1]
42 {
43 return std::move(r1);
44 } );
45 BOOST_TEST_EQ(r2.value(), 1);
46 }
47
48 return boost::report_errors();
49}