2
0
mirror of https://github.com/boostorg/leaf.git synced 2026-01-27 06:52:14 +00:00
Files
leaf/test/result_capture_load_test.cpp

57 lines
1.1 KiB
C++

// Copyright (c) 2018-2019 Emil Dotchevski
// Copyright (c) 2018-2019 Second Spectrum, Inc.
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
#include <boost/leaf/capture.hpp>
#include <boost/leaf/result.hpp>
#include <boost/leaf/handle_error.hpp>
#include "boost/core/lightweight_test.hpp"
namespace leaf = boost::leaf;
struct info
{
int value;
};
int main()
{
auto handle_error = [ ]( leaf::error_info const & error )
{
return leaf::remote_handle_all( error,
[ ]( info x )
{
BOOST_TEST_EQ(x.value, 1);
return 1;
},
[ ]
{
return 2;
} );
};
leaf::result<void> r = leaf::capture( leaf::make_shared_context(&handle_error),
[ ]() -> leaf::result<void>
{
return leaf::new_error();
} );
r.load( info{1} );
int rr = leaf::remote_try_handle_all(
[&]() -> leaf::result<int>
{
LEAF_CHECK(r);
return 0;
},
[&]( leaf::error_info const & error )
{
return handle_error(error);
} );
BOOST_TEST_EQ(rr, 1);
return boost::report_errors();
}