// Copyright 2018-2022 Emil Dotchevski and Reverge Studios, 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) #ifdef BOOST_LEAF_TEST_SINGLE_HEADER # include "leaf.hpp" #else # include # include # include #endif #include "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}, []{ return info<3>{3}; }); leaf::result r4 = r3.load([](info<42> & x){ ++x.value; }); leaf::result r5 = r4.load([](info<42> & x){ ++x.value; }, [](info<1> & x){ ++x.value; }); return r5; } int main() { { int r = leaf::try_handle_all( [] { return test(); }, []( leaf::match_value, 42>, leaf::match_value, 1>, leaf::match_value, 2>, leaf::match_value, 3> ) { return 1; }, [] { return 2; } ); BOOST_TEST_EQ(r, 1); } { int r = leaf::try_handle_all( []() -> leaf::result { BOOST_LEAF_CHECK(test()); return 0; }, []( leaf::match_value, 42>, leaf::match_value, 1>, leaf::match_value, 2>, leaf::match_value, 3> ) { return 1; }, [] { return 2; } ); BOOST_TEST_EQ(r, 1); } return boost::report_errors(); }