2
0
mirror of https://github.com/boostorg/leaf.git synced 2026-01-30 20:02:15 +00:00
Files
leaf/test/capture_result_state_test.cpp
2019-01-15 11:28:17 -08:00

60 lines
1.0 KiB
C++

// Copyright (c) 2018 Emil Dotchevski
// Copyright (c) 2018 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_result.hpp>
#include <boost/leaf/handle.hpp>
#include "boost/core/lightweight_test.hpp"
namespace leaf = boost::leaf;
int count = 0;
template <int>
struct info
{
info() noexcept
{
++count;
}
info( info const & ) noexcept
{
++count;
}
~info() noexcept
{
--count;
}
};
namespace boost { namespace leaf {
template <int I> struct is_error_type<info<I>>: public std::true_type { };
} }
int main()
{
auto f = leaf::capture_result<info<1>, info<2>, info<3>>(
[ ]() -> leaf::result<void>
{
return leaf::new_error( info<1>{}, info<3>{} );
} );
leaf::handle_all(
[&f]
{
BOOST_TEST(count==0);
auto r = f();
BOOST_TEST(count==2);
return r;
},
[ ]
{
} );
BOOST_TEST(count==0);
return boost::report_errors();
}