// 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 #include #include "boost/core/lightweight_test.hpp" namespace leaf = boost::leaf; template struct info { int value; }; struct my_exception: std::exception { }; int main() { { leaf::result r = leaf::try_( [ ]() -> leaf::result { return 42; }, [ ]() -> leaf::result { return { }; } ); BOOST_TEST(r && r.value()==42); } { leaf::result r = leaf::try_( [ ]() -> leaf::result { throw leaf::exception( my_exception(), info<1>{1} ); }, [ ]( leaf::catch_, info<1> const & x ) -> leaf::result { BOOST_TEST(x.value==1); return 42; } ); BOOST_TEST(r && r.value()==42); } { leaf::result r = leaf::try_( [ ]() -> leaf::result { return leaf::new_error( info<1>{1} ); }, [ ]( info<1> const & x ) -> leaf::result { BOOST_TEST(x.value==1); return 42; } ); BOOST_TEST(r && r.value()==42); } return boost::report_errors(); }