// Copyright (c) 2018-2021 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) #include #include #ifdef BOOST_LEAF_TEST_SINGLE_HEADER # include "leaf.hpp" #else # include #endif #include "lightweight_test.hpp" #include namespace leaf = boost::leaf; template struct info { int value; }; leaf::result f12() { return leaf::new_error( info<1>{1}, info<2>{2} ); } leaf::result f23() { return leaf::new_error( info<2>{2}, info<3>{3} ); } int main() { { int r = leaf::try_handle_all( []() -> leaf::result { leaf::result r1 = f12(); (void) r1; leaf::result r2 = f23(); return r2.error(); }, []( info<1> ) { return 1; }, []( info<2> const & x, info<3> const & y ) { BOOST_TEST_EQ(x.value, 2); BOOST_TEST_EQ(y.value, 3); return 2; }, [] { return 3; } ); BOOST_TEST_EQ(r, 2); } #ifndef BOOST_LEAF_NO_EXCEPTIONS { int r = leaf::try_catch( []() -> int { try { throw leaf::exception(info<4>{4}); } catch(...) { } throw std::exception{}; }, []( std::exception const &, info<4> ) { return 1; }, []( std::exception const & ) { return 2; } ); BOOST_TEST_EQ(r, 2); } #endif return boost::report_errors(); }