// 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 #include #include "boost/core/lightweight_test.hpp" namespace leaf = boost::leaf; template struct info { int value; }; template leaf::result test() { leaf::result r1 = leaf::new_error(info<42>{40}); leaf::result & r2 = r1.load(info<1>{}); leaf::result & r3 = r2.load(info<2>{2}, info<3>{3}); leaf::result & r4 = r3.accumulate([ ](info<42> & x){ ++x.value; }); leaf::result & r5 = r4.accumulate([ ](info<42> & x){ ++x.value; }, [ ](info<1> & x){ ++x.value; }); return r5; } int main() { { int r = leaf::handle_all( [ ] { return test(); }, [ ]( leaf::match, 42>, leaf::match, 1>, leaf::match, 2>, leaf::match, 3> ) { return 1; }, [ ] { return 2; } ); BOOST_TEST_EQ(r, 1); } { int r = leaf::handle_all( [ ]() -> leaf::result { LEAF_CHECK(test()); return 0; }, [ ]( leaf::match, 42>, leaf::match, 1>, leaf::match, 2>, leaf::match, 3> ) { return 1; }, [ ] { return 2; } ); BOOST_TEST_EQ(r, 1); } return boost::report_errors(); }