diff --git a/examples/asio_beast_leaf_rpc.cpp b/examples/asio_beast_leaf_rpc.cpp index 2c85b36..a8975cb 100644 --- a/examples/asio_beast_leaf_rpc.cpp +++ b/examples/asio_beast_leaf_rpc.cpp @@ -118,7 +118,7 @@ auto async_demo_rpc(AsyncStream &stream, ErrorContext &error_context, Completion leaf::result result_continue_execution; { auto active_context = activate_context(m_error_context); - auto load = leaf::preload(e_last_operation{m_data.response ? "async_demo_rpc::continuation-write" + auto load = leaf::on_error(e_last_operation{m_data.response ? "async_demo_rpc::continuation-write" : "async_demo_rpc::continuation-read"}); if (ec == http::error::end_of_stream) { // The remote side closed the connection. @@ -175,7 +175,7 @@ auto async_demo_rpc(AsyncStream &stream, ErrorContext &error_context, Completion }; // We are in the "initiation" part of the async operation. - [[maybe_unused]] auto load = leaf::preload(e_last_operation{"async_demo_rpc::initiation"}); + [[maybe_unused]] auto load = leaf::on_error(e_last_operation{"async_demo_rpc::initiation"}); return net::async_initiate)>(initiation, token, &stream, &error_context); } @@ -310,8 +310,7 @@ leaf::result execute_command(std::string_view line) { auto command = words.front(); words.pop_front(); - auto load_cmd = leaf::preload(e_command{command}); - auto load_http_status = leaf::preload(e_http_status{http::status::bad_request}); + auto load_cmd = leaf::on_error(e_command{command}, e_http_status{http::status::bad_request}); std::string response; if (command == "error-quit") { @@ -496,7 +495,7 @@ int main(int argc, char **argv) { // (e.g. ports less than 1024 if not running as root) return leaf::remote_try_handle_all( [&]() -> leaf::result { - auto load = leaf::preload(e_last_operation{"main"}); + auto load = leaf::on_error(e_last_operation{"main"}); if (argc != 3) { std::cerr << "Usage: " << argv[0] << "
" << std::endl; std::cerr << "Example:\n " << argv[0] << " 0.0.0.0 8080" << std::endl; diff --git a/examples/error_log.cpp b/examples/error_log.cpp index 075cc74..f76a93d 100644 --- a/examples/error_log.cpp +++ b/examples/error_log.cpp @@ -3,7 +3,7 @@ // 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) -// This program demonstrates the use of leaf::accumulate to print the path an error takes +// This program demonstrates the use of leaf::on_error to print the path an error takes // as is bubbles up the call stack. The printing code only runs if: // - An error occurs, and // - A handler that takes e_error_log argument is present. @@ -12,7 +12,7 @@ // This example is similar to error_trace, except the path the error takes is not captured, // only printed. -#include +#include #include #include #include @@ -23,7 +23,6 @@ namespace leaf = boost::leaf; // The error log is activated only if an error-handling scope provides a handler for e_error_log. -// This activation logic applies to any type passed to leaf::accumulate. struct e_error_log { struct rec @@ -52,7 +51,7 @@ struct e_error_log // The ERROR_LOG macro is designed for use in functions that detect or forward errors // up the call stack. If an error occurs, and if an error-handling scope provides a handler // for e_error_log, the supplied lambda is executed as the error bubbles up. -#define ERROR_LOG auto _log = leaf::accumulate( []( e_error_log & log ) { log << e_error_log::rec{__FILE__, __LINE__}; } ) +#define ERROR_LOG auto _log = leaf::on_error( []( e_error_log & log ) { log << e_error_log::rec{__FILE__, __LINE__}; } ) // Each function in the sequence below calls the previous function, and each function has // failure_percent chance of failing. If a failure occurs, the ERROR_LOG macro will cause diff --git a/examples/error_trace.cpp b/examples/error_trace.cpp index edcaf9a..38aa631 100644 --- a/examples/error_trace.cpp +++ b/examples/error_trace.cpp @@ -3,7 +3,7 @@ // 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) -// This program demonstrates the use of leaf::accumulate to capture the path an error takes +// This program demonstrates the use of leaf::on_error to capture the path an error takes // as is bubbles up the call stack. The error path-capturing code only runs if: // - An error occurs, and // - A handler that takes e_error_trace argument is present. @@ -12,7 +12,7 @@ // This example is similar to error_log, except the path the error takes is captured and // recorded in a std::deque, rather than just printed in-place. -#include +#include #include #include #include @@ -24,7 +24,6 @@ namespace leaf = boost::leaf; // The error trace is activated only if an error-handling scope provides a handler for e_error_trace. -// This activation logic applies to any type passed to leaf::accumulate. struct e_error_trace { struct rec @@ -50,7 +49,7 @@ struct e_error_trace // The ERROR_TRACE macro is designed for use in functions that detect or forward errors // up the call stack. If an error occurs, and if an error-handling scope provides a handler // for e_error_trace, the supplied lambda is executed as the error bubbles up. -#define ERROR_TRACE auto _trace = leaf::accumulate( []( e_error_trace & tr ) { tr.value.emplace_front(e_error_trace::rec{__FILE__, __LINE__}); } ) +#define ERROR_TRACE auto _trace = leaf::on_error( []( e_error_trace & tr ) { tr.value.emplace_front(e_error_trace::rec{__FILE__, __LINE__}); } ) // Each function in the sequence below calls the previous function, and each function has // failure_percent chance of failing. If a failure occurs, the ERROR_TRACE macro will cause diff --git a/examples/lua_callback_eh.cpp b/examples/lua_callback_eh.cpp index 4c0177e..e0f326c 100644 --- a/examples/lua_callback_eh.cpp +++ b/examples/lua_callback_eh.cpp @@ -13,7 +13,7 @@ extern "C" { } #include #include -#include +#include #include #include @@ -84,7 +84,7 @@ int call_lua( lua_State * L ) { // Something went wrong with the call, so we'll throw std::exception. // This is definitely not a do_work failure, because it throws on error. - auto load = leaf::preload( e_lua_error_message{lua_tostring(L,1)} ); + auto load = leaf::on_error( e_lua_error_message{lua_tostring(L,1)} ); lua_pop(L,1); throw leaf::exception( std::exception(), e_lua_pcall_error{err} ); } diff --git a/examples/lua_callback_result.cpp b/examples/lua_callback_result.cpp index 363f27e..5763fa4 100644 --- a/examples/lua_callback_result.cpp +++ b/examples/lua_callback_result.cpp @@ -13,7 +13,7 @@ extern "C" { } #include #include -#include +#include #include #include @@ -88,7 +88,7 @@ leaf::result call_lua( lua_State * L ) leaf::augment_id augment; if( int err=lua_pcall(L,0,1,0) ) // Ask Lua to call the global function call_do_work. { - auto load = leaf::preload( e_lua_error_message{lua_tostring(L,1)} ); + auto load = leaf::on_error( e_lua_error_message{lua_tostring(L,1)} ); lua_pop(L,1); // get_error will return the error_id generated in our Lua callback. This is the diff --git a/examples/print_file_eh.cpp b/examples/print_file_eh.cpp index 6b5f5d8..8d8ea21 100644 --- a/examples/print_file_eh.cpp +++ b/examples/print_file_eh.cpp @@ -11,7 +11,7 @@ #include #include -#include +#include #include #include #include @@ -58,7 +58,7 @@ int main( int argc, char const * argv[] ) { char const * file_name = parse_command_line(argc,argv); - auto load = leaf::preload( leaf::e_file_name{file_name} ); + auto load = leaf::on_error( leaf::e_file_name{file_name} ); std::shared_ptr f = file_open( file_name ); @@ -67,7 +67,7 @@ int main( int argc, char const * argv[] ) std::string buffer( 1 + s, '\0' ); file_read(*f,&buffer[0],buffer.size()-1); - auto propagate2 = leaf::defer([] { return leaf::e_errno{errno}; } ); + auto propagate2 = leaf::on_error([] { return leaf::e_errno{errno}; } ); std::cout << buffer; std::cout.flush(); @@ -164,7 +164,7 @@ std::shared_ptr file_open( char const * file_name ) int file_size( FILE & f ) { // All exceptions escaping this function will automatically load errno. - auto load = leaf::defer( [] { return leaf::e_errno{errno}; } ); + auto load = leaf::on_error( [] { return leaf::e_errno{errno}; } ); if( fseek(&f,0,SEEK_END) ) throw leaf::exception(input_file_size_error()); diff --git a/examples/print_file_outcome_result.cpp b/examples/print_file_outcome_result.cpp index 6326367..89d6c4e 100644 --- a/examples/print_file_outcome_result.cpp +++ b/examples/print_file_outcome_result.cpp @@ -11,7 +11,7 @@ #include #include -#include +#include #include #include #include @@ -65,7 +65,7 @@ int main( int argc, char const * argv[] ) { LEAF_AUTO(file_name, parse_command_line(argc,argv)); - auto load = leaf::preload( leaf::e_file_name{file_name} ); + auto load = leaf::on_error( leaf::e_file_name{file_name} ); LEAF_AUTO(f, file_open(file_name)); @@ -172,7 +172,7 @@ result> file_open( char const * file_name ) result file_size( FILE & f ) { // All exceptions escaping this function will automatically load errno. - auto load = leaf::defer([] { return leaf::e_errno{errno}; }); + auto load = leaf::on_error([] { return leaf::e_errno{errno}; }); if( fseek(&f,0,SEEK_END) ) return leaf::new_error(input_file_size_error).to_error_code(); diff --git a/examples/print_file_result.cpp b/examples/print_file_result.cpp index 319d033..5b8926c 100644 --- a/examples/print_file_result.cpp +++ b/examples/print_file_result.cpp @@ -11,7 +11,7 @@ #include #include -#include +#include #include #include #include @@ -56,7 +56,7 @@ int main( int argc, char const * argv[] ) { LEAF_AUTO(file_name, parse_command_line(argc,argv)); - auto load = leaf::preload( leaf::e_file_name{file_name} ); + auto load = leaf::on_error( leaf::e_file_name{file_name} ); LEAF_AUTO(f, file_open(file_name)); @@ -163,7 +163,7 @@ leaf::result> file_open( char const * file_name ) leaf::result file_size( FILE & f ) { // All exceptions escaping this function will automatically load errno. - auto load = leaf::defer([] { return leaf::e_errno{errno}; }); + auto load = leaf::on_error([] { return leaf::e_errno{errno}; }); if( fseek(&f,0,SEEK_END) ) return leaf::new_error(input_file_size_error); diff --git a/include/boost/leaf/all.hpp b/include/boost/leaf/all.hpp index eb17b85..a77152b 100644 --- a/include/boost/leaf/all.hpp +++ b/include/boost/leaf/all.hpp @@ -1336,6 +1336,32 @@ namespace boost { namespace leaf { //////////////////////////////////////// + namespace leaf_detail + { + template ::arity> + struct load_item; + + template + struct load_item + { + LEAF_CONSTEXPR static int load( int err_id, E && e ) noexcept + { + return load_slot(err_id, std::forward(e)); + } + }; + + template + struct load_item + { + LEAF_CONSTEXPR static int load( int err_id, F && f ) noexcept + { + return accumulate_slot(err_id, std::forward(f)); + } + }; + } + + //////////////////////////////////////// + namespace leaf_detail { class leaf_category: public std::error_category @@ -1361,7 +1387,7 @@ namespace boost { namespace leaf { { if( int err_id = ec.value() ) { - std::error_category const & cat = leaf_detail::get_error_category<>::cat; + std::error_category const & cat = get_error_category<>::cat; if( &ec.category()==&cat ) { BOOST_LEAF_ASSERT((err_id&3)==1); @@ -1369,8 +1395,8 @@ namespace boost { namespace leaf { } else { - err_id = leaf_detail::new_id(); - leaf_detail::load_slot(err_id,ec); + err_id = new_id(); + (void) load_slot(err_id, ec); return (err_id&~3)|1; } } @@ -1380,7 +1406,7 @@ namespace boost { namespace leaf { inline bool is_error_id( std::error_code const & ec ) noexcept { - bool res = (&ec.category() == &leaf_detail::get_error_category<>::cat); + bool res = (&ec.category() == &get_error_category<>::cat); BOOST_LEAF_ASSERT(!res || !ec.value() || ((ec.value()&3)==1)); return res; } @@ -1425,28 +1451,12 @@ namespace boost { namespace leaf { return *this; } - template - LEAF_CONSTEXPR error_id load( E && ... e ) const noexcept + template + LEAF_CONSTEXPR error_id load( Item && ... item ) const noexcept { if( int err_id = value() ) { - auto _ = { leaf_detail::load_slot(err_id, std::forward(e))... }; - (void) _; - } - return *this; - } - - LEAF_CONSTEXPR error_id accumulate() const noexcept - { - return *this; - } - - template - LEAF_CONSTEXPR error_id accumulate( F && ... f ) const noexcept - { - if( int err_id = value() ) - { - auto _ = { leaf_detail::accumulate_slot(err_id, std::forward(f))... }; + auto _ = { leaf_detail::load_item::load(err_id, std::forward(item))... }; (void) _; } return *this; @@ -1783,8 +1793,8 @@ namespace boost { namespace leaf { #endif // <<< #include #line 18 "boost/leaf/capture.hpp" -// >>> #include -#line 1 "boost/leaf/preload.hpp" +// >>> #include +#line 1 "boost/leaf/on_error.hpp" #ifndef LEAF_25AF99F6DC6F11E8803DE9BC9723C688 #define LEAF_25AF99F6DC6F11E8803DE9BC9723C688 @@ -1875,12 +1885,7 @@ namespace boost { namespace leaf { { LEAF_CONSTEXPR static void trigger( Tuple const &, int ) noexcept { } }; - } // leaf_detail - //////////////////////////////////////// - - namespace leaf_detail - { template class preloaded_item { @@ -1890,7 +1895,7 @@ namespace boost { namespace leaf { public: - LEAF_CONSTEXPR explicit preloaded_item( E && e ): + LEAF_CONSTEXPR preloaded_item( E && e ): s_(tl_slot_ptr()), e_(std::forward(e)) { @@ -1916,51 +1921,6 @@ namespace boost { namespace leaf { } }; - template - class preloaded - { - preloaded & operator=( preloaded const & ) = delete; - - std::tuple...> p_; - bool moved_; - augment_id id_; - - public: - - LEAF_CONSTEXPR explicit preloaded( E && ... e ): - p_(preloaded_item(std::forward(e))...), - moved_(false) - { - } - - LEAF_CONSTEXPR preloaded( preloaded && x ) noexcept: - p_(std::move(x.p_)), - moved_(false), - id_(std::move(x.id_)) - { - x.moved_ = true; - } - - ~preloaded() noexcept - { - if( moved_ ) - return; - if( auto id = id_.check_id() ) - leaf_detail::tuple_for_each_preload::trigger(p_,id); - } - }; - } // leaf_detail - - template - LEAF_NODISCARD LEAF_CONSTEXPR inline leaf_detail::preloaded preload( E && ... e ) - { - return leaf_detail::preloaded(std::forward(e)...); - } - - //////////////////////////////////////// - - namespace leaf_detail - { template class deferred_item { @@ -1970,7 +1930,7 @@ namespace boost { namespace leaf { public: - LEAF_CONSTEXPR explicit deferred_item( F && f ) noexcept: + LEAF_CONSTEXPR deferred_item( F && f ) noexcept: s_(tl_slot_ptr()), f_(std::forward(f)) { @@ -1996,50 +1956,6 @@ namespace boost { namespace leaf { } }; - template - class deferred - { - deferred & operator=( deferred const & ) = delete; - std::tuple...> d_; - bool moved_; - augment_id id_; - - public: - - LEAF_CONSTEXPR explicit deferred( F && ... f ) noexcept: - d_(deferred_item(std::forward(f))...), - moved_(false) - { - } - - LEAF_CONSTEXPR deferred( deferred && x ) noexcept: - d_(std::move(x.d_)), - moved_(false), - id_(std::move(x.id_)) - { - x.moved_ = true; - } - - ~deferred() noexcept - { - if( moved_ ) - return; - if( auto id = id_.check_id() ) - leaf_detail::tuple_for_each_preload::trigger(d_,id); - } - }; - } // leaf_detail - - template - LEAF_NODISCARD LEAF_CONSTEXPR inline leaf_detail::deferred defer( F && ... f ) noexcept - { - return leaf_detail::deferred(std::forward(f)...); - } - - //////////////////////////////////////// - - namespace leaf_detail - { template , int arity = function_traits::arity> class accumulating_item; @@ -2052,7 +1968,7 @@ namespace boost { namespace leaf { public: - LEAF_CONSTEXPR explicit accumulating_item( F && f ) noexcept: + LEAF_CONSTEXPR accumulating_item( F && f ) noexcept: s_(tl_slot_ptr()), f_(std::forward(f)) { @@ -2069,50 +1985,72 @@ namespace boost { namespace leaf { } }; - template - class accumulating + template + class preloaded { - accumulating & operator=( accumulating const & ) = delete; - std::tuple...> a_; + preloaded & operator=( preloaded const & ) = delete; + + std::tuple p_; bool moved_; augment_id id_; public: - LEAF_CONSTEXPR explicit accumulating( F && ... f ) noexcept: - a_(accumulating_item(std::forward(f))...), + LEAF_CONSTEXPR explicit preloaded( Item && ... i ): + p_(std::forward(i)...), moved_(false) { } - LEAF_CONSTEXPR accumulating( accumulating && x ) noexcept: - a_(std::move(x.a_)), + LEAF_CONSTEXPR preloaded( preloaded && x ) noexcept: + p_(std::move(x.p_)), moved_(false), id_(std::move(x.id_)) { x.moved_ = true; } - ~accumulating() noexcept + ~preloaded() noexcept { if( moved_ ) return; if( auto id = id_.check_id() ) - leaf_detail::tuple_for_each_preload::trigger(a_,id); + leaf_detail::tuple_for_each_preload::trigger(p_,id); } }; + + template ::arity> + struct deduce_item_type; + + template + struct deduce_item_type + { + using type = preloaded_item; + }; + + template + struct deduce_item_type + { + using type = deferred_item; + }; + + template + struct deduce_item_type + { + using type = accumulating_item; + }; } // leaf_detail - template - LEAF_NODISCARD LEAF_CONSTEXPR inline leaf_detail::accumulating accumulate( F && ... f ) noexcept + template + LEAF_NODISCARD LEAF_CONSTEXPR inline leaf_detail::preloaded::type...> on_error( Item && ... i ) { - return leaf_detail::accumulating(std::forward(f)...); + return leaf_detail::preloaded::type...>(std::forward(i)...); } } } #endif -// <<< #include +// <<< #include #line 19 "boost/leaf/capture.hpp" #include @@ -4697,16 +4635,10 @@ namespace boost { namespace leaf { return error_result{*this}; } - template - LEAF_CONSTEXPR error_id load( E && ... e ) noexcept + template + LEAF_CONSTEXPR error_id load( Item && ... item ) noexcept { - return error_id(error()).load(std::forward(e)...); - } - - template - LEAF_CONSTEXPR error_id accumulate( F && ... f ) noexcept - { - return error_id(error()).accumulate(std::forward(f)...); + return error_id(error()).load(std::forward(item)...); } }; @@ -4775,7 +4707,6 @@ namespace boost { namespace leaf { using base::get_error_id; using base::error; using base::load; - using base::accumulate; }; //////////////////////////////////////// diff --git a/include/boost/leaf/capture.hpp b/include/boost/leaf/capture.hpp index 9ff550a..dbbfa92 100644 --- a/include/boost/leaf/capture.hpp +++ b/include/boost/leaf/capture.hpp @@ -15,7 +15,7 @@ #endif #include -#include +#include #include namespace boost { namespace leaf { diff --git a/include/boost/leaf/detail/all.hpp b/include/boost/leaf/detail/all.hpp index 62a6725..3db0132 100644 --- a/include/boost/leaf/detail/all.hpp +++ b/include/boost/leaf/detail/all.hpp @@ -16,7 +16,7 @@ #ifndef LEAF_NO_EXCEPTIONS # include #endif -#include +#include #include #endif diff --git a/include/boost/leaf/error.hpp b/include/boost/leaf/error.hpp index fc5f407..2f6a7f2 100644 --- a/include/boost/leaf/error.hpp +++ b/include/boost/leaf/error.hpp @@ -375,6 +375,41 @@ namespace boost { namespace leaf { //////////////////////////////////////// + namespace leaf_detail + { + template ::arity> + struct load_item; + + template + struct load_item + { + LEAF_CONSTEXPR static int load( int err_id, E && e ) noexcept + { + return load_slot(err_id, std::forward(e)); + } + }; + + template + struct load_item + { + LEAF_CONSTEXPR static int load( int err_id, F && f ) noexcept + { + return load_slot(err_id, std::forward(f)()); + } + }; + + template + struct load_item + { + LEAF_CONSTEXPR static int load( int err_id, F && f ) noexcept + { + return accumulate_slot(err_id, std::forward(f)); + } + }; + } + + //////////////////////////////////////// + namespace leaf_detail { class leaf_category: public std::error_category @@ -400,7 +435,7 @@ namespace boost { namespace leaf { { if( int err_id = ec.value() ) { - std::error_category const & cat = leaf_detail::get_error_category<>::cat; + std::error_category const & cat = get_error_category<>::cat; if( &ec.category()==&cat ) { BOOST_LEAF_ASSERT((err_id&3)==1); @@ -408,8 +443,8 @@ namespace boost { namespace leaf { } else { - err_id = leaf_detail::new_id(); - leaf_detail::load_slot(err_id,ec); + err_id = new_id(); + (void) load_slot(err_id, ec); return (err_id&~3)|1; } } @@ -419,7 +454,7 @@ namespace boost { namespace leaf { inline bool is_error_id( std::error_code const & ec ) noexcept { - bool res = (&ec.category() == &leaf_detail::get_error_category<>::cat); + bool res = (&ec.category() == &get_error_category<>::cat); BOOST_LEAF_ASSERT(!res || !ec.value() || ((ec.value()&3)==1)); return res; } @@ -464,28 +499,12 @@ namespace boost { namespace leaf { return *this; } - template - LEAF_CONSTEXPR error_id load( E && ... e ) const noexcept + template + LEAF_CONSTEXPR error_id load( Item && ... item ) const noexcept { if( int err_id = value() ) { - auto _ = { leaf_detail::load_slot(err_id, std::forward(e))... }; - (void) _; - } - return *this; - } - - LEAF_CONSTEXPR error_id accumulate() const noexcept - { - return *this; - } - - template - LEAF_CONSTEXPR error_id accumulate( F && ... f ) const noexcept - { - if( int err_id = value() ) - { - auto _ = { leaf_detail::accumulate_slot(err_id, std::forward(f))... }; + auto _ = { leaf_detail::load_item::load(err_id, std::forward(item))... }; (void) _; } return *this; diff --git a/include/boost/leaf/preload.hpp b/include/boost/leaf/on_error.hpp similarity index 62% rename from include/boost/leaf/preload.hpp rename to include/boost/leaf/on_error.hpp index 1ba711b..406efae 100644 --- a/include/boost/leaf/preload.hpp +++ b/include/boost/leaf/on_error.hpp @@ -89,12 +89,7 @@ namespace boost { namespace leaf { { LEAF_CONSTEXPR static void trigger( Tuple const &, int ) noexcept { } }; - } // leaf_detail - //////////////////////////////////////// - - namespace leaf_detail - { template class preloaded_item { @@ -104,7 +99,7 @@ namespace boost { namespace leaf { public: - LEAF_CONSTEXPR explicit preloaded_item( E && e ): + LEAF_CONSTEXPR preloaded_item( E && e ): s_(tl_slot_ptr()), e_(std::forward(e)) { @@ -130,51 +125,6 @@ namespace boost { namespace leaf { } }; - template - class preloaded - { - preloaded & operator=( preloaded const & ) = delete; - - std::tuple...> p_; - bool moved_; - augment_id id_; - - public: - - LEAF_CONSTEXPR explicit preloaded( E && ... e ): - p_(preloaded_item(std::forward(e))...), - moved_(false) - { - } - - LEAF_CONSTEXPR preloaded( preloaded && x ) noexcept: - p_(std::move(x.p_)), - moved_(false), - id_(std::move(x.id_)) - { - x.moved_ = true; - } - - ~preloaded() noexcept - { - if( moved_ ) - return; - if( auto id = id_.check_id() ) - leaf_detail::tuple_for_each_preload::trigger(p_,id); - } - }; - } // leaf_detail - - template - LEAF_NODISCARD LEAF_CONSTEXPR inline leaf_detail::preloaded preload( E && ... e ) - { - return leaf_detail::preloaded(std::forward(e)...); - } - - //////////////////////////////////////// - - namespace leaf_detail - { template class deferred_item { @@ -184,7 +134,7 @@ namespace boost { namespace leaf { public: - LEAF_CONSTEXPR explicit deferred_item( F && f ) noexcept: + LEAF_CONSTEXPR deferred_item( F && f ) noexcept: s_(tl_slot_ptr()), f_(std::forward(f)) { @@ -210,50 +160,6 @@ namespace boost { namespace leaf { } }; - template - class deferred - { - deferred & operator=( deferred const & ) = delete; - std::tuple...> d_; - bool moved_; - augment_id id_; - - public: - - LEAF_CONSTEXPR explicit deferred( F && ... f ) noexcept: - d_(deferred_item(std::forward(f))...), - moved_(false) - { - } - - LEAF_CONSTEXPR deferred( deferred && x ) noexcept: - d_(std::move(x.d_)), - moved_(false), - id_(std::move(x.id_)) - { - x.moved_ = true; - } - - ~deferred() noexcept - { - if( moved_ ) - return; - if( auto id = id_.check_id() ) - leaf_detail::tuple_for_each_preload::trigger(d_,id); - } - }; - } // leaf_detail - - template - LEAF_NODISCARD LEAF_CONSTEXPR inline leaf_detail::deferred defer( F && ... f ) noexcept - { - return leaf_detail::deferred(std::forward(f)...); - } - - //////////////////////////////////////// - - namespace leaf_detail - { template , int arity = function_traits::arity> class accumulating_item; @@ -266,7 +172,7 @@ namespace boost { namespace leaf { public: - LEAF_CONSTEXPR explicit accumulating_item( F && f ) noexcept: + LEAF_CONSTEXPR accumulating_item( F && f ) noexcept: s_(tl_slot_ptr()), f_(std::forward(f)) { @@ -283,44 +189,66 @@ namespace boost { namespace leaf { } }; - template - class accumulating + template + class preloaded { - accumulating & operator=( accumulating const & ) = delete; - std::tuple...> a_; + preloaded & operator=( preloaded const & ) = delete; + + std::tuple p_; bool moved_; augment_id id_; public: - LEAF_CONSTEXPR explicit accumulating( F && ... f ) noexcept: - a_(accumulating_item(std::forward(f))...), + LEAF_CONSTEXPR explicit preloaded( Item && ... i ): + p_(std::forward(i)...), moved_(false) { } - LEAF_CONSTEXPR accumulating( accumulating && x ) noexcept: - a_(std::move(x.a_)), + LEAF_CONSTEXPR preloaded( preloaded && x ) noexcept: + p_(std::move(x.p_)), moved_(false), id_(std::move(x.id_)) { x.moved_ = true; } - ~accumulating() noexcept + ~preloaded() noexcept { if( moved_ ) return; if( auto id = id_.check_id() ) - leaf_detail::tuple_for_each_preload::trigger(a_,id); + leaf_detail::tuple_for_each_preload::trigger(p_,id); } }; + + template ::arity> + struct deduce_item_type; + + template + struct deduce_item_type + { + using type = preloaded_item; + }; + + template + struct deduce_item_type + { + using type = deferred_item; + }; + + template + struct deduce_item_type + { + using type = accumulating_item; + }; } // leaf_detail - template - LEAF_NODISCARD LEAF_CONSTEXPR inline leaf_detail::accumulating accumulate( F && ... f ) noexcept + template + LEAF_NODISCARD LEAF_CONSTEXPR inline leaf_detail::preloaded::type...> on_error( Item && ... i ) { - return leaf_detail::accumulating(std::forward(f)...); + return leaf_detail::preloaded::type...>(std::forward(i)...); } } } diff --git a/include/boost/leaf/result.hpp b/include/boost/leaf/result.hpp index c54b8e6..a512355 100644 --- a/include/boost/leaf/result.hpp +++ b/include/boost/leaf/result.hpp @@ -311,16 +311,10 @@ namespace boost { namespace leaf { return error_result{*this}; } - template - LEAF_CONSTEXPR error_id load( E && ... e ) noexcept + template + LEAF_CONSTEXPR error_id load( Item && ... item ) noexcept { - return error_id(error()).load(std::forward(e)...); - } - - template - LEAF_CONSTEXPR error_id accumulate( F && ... f ) noexcept - { - return error_id(error()).accumulate(std::forward(f)...); + return error_id(error()).load(std::forward(item)...); } }; @@ -389,7 +383,6 @@ namespace boost { namespace leaf { using base::get_error_id; using base::error; using base::load; - using base::accumulate; }; //////////////////////////////////////// diff --git a/test/_hpp_preload_test.cpp b/test/_hpp_preload_test.cpp index a4a35c1..f43f741 100644 --- a/test/_hpp_preload_test.cpp +++ b/test/_hpp_preload_test.cpp @@ -3,6 +3,6 @@ // 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 +#include int main() { return 0; } diff --git a/test/accumulate_basic_test.cpp b/test/accumulate_basic_test.cpp index c8d2093..93cde7d 100644 --- a/test/accumulate_basic_test.cpp +++ b/test/accumulate_basic_test.cpp @@ -3,7 +3,7 @@ // 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 #include #include "lightweight_test.hpp" @@ -18,13 +18,13 @@ struct info leaf::error_id g() { - auto load = leaf::accumulate( [](info<1> & x) {++x.value;} ); + auto load = leaf::on_error( [](info<1> & x) {++x.value;} ); return leaf::new_error(); } leaf::error_id f() { - auto load = leaf::accumulate( [](info<1> & x) {++x.value;}, [](info<2> & x) {++x.value;} ); + auto load = leaf::on_error( [](info<1> & x) {++x.value;}, [](info<2> & x) {++x.value;} ); return g(); } diff --git a/test/accumulate_nested_error_exception_test.cpp b/test/accumulate_nested_error_exception_test.cpp index fb68906..d079c87 100644 --- a/test/accumulate_nested_error_exception_test.cpp +++ b/test/accumulate_nested_error_exception_test.cpp @@ -16,7 +16,7 @@ int main() #else -#include +#include #include #include #include "lightweight_test.hpp" @@ -31,14 +31,13 @@ struct info void f0() { - auto load = leaf::accumulate( []( info<0> & ) { } ); + auto load = leaf::on_error( []( info<0> & ) { } ); throw leaf::exception(std::exception(), info<2>{2} ); } void f1() { - auto propagate1 = leaf::preload( info<0>{-1}, info<2>{-1} ); - auto propagate2 = leaf::accumulate( []( info<1> & x ) {++x.value;} ); + auto propagate = leaf::on_error( info<0>{-1}, info<2>{-1}, []( info<1> & x ) {++x.value;} ); f0(); } diff --git a/test/accumulate_nested_error_result_test.cpp b/test/accumulate_nested_error_result_test.cpp index a00de5c..8c70ab5 100644 --- a/test/accumulate_nested_error_result_test.cpp +++ b/test/accumulate_nested_error_result_test.cpp @@ -3,7 +3,7 @@ // 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 #include #include "lightweight_test.hpp" @@ -18,14 +18,13 @@ struct info leaf::error_id f0() { - auto load = leaf::accumulate( []( info<0> & ) { } ); + auto load = leaf::on_error( []( info<0> & ) { } ); return leaf::new_error( info<2>{2} ); } leaf::error_id f1() { - auto propagate1 = leaf::preload( info<0>{-1}, info<2>{-1} ); - auto propagate2 = leaf::accumulate( []( info<1> & x ) {++x.value;} ); + auto propagate = leaf::on_error( info<0>{-1}, info<2>{-1}, []( info<1> & x ) {++x.value;} ); return f0(); } diff --git a/test/accumulate_nested_new_error_exception_test.cpp b/test/accumulate_nested_new_error_exception_test.cpp index 3f08dbc..a79266c 100644 --- a/test/accumulate_nested_new_error_exception_test.cpp +++ b/test/accumulate_nested_new_error_exception_test.cpp @@ -16,7 +16,7 @@ int main() #else -#include +#include #include #include #include "lightweight_test.hpp" @@ -31,13 +31,13 @@ struct info void f0() { - auto load = leaf::preload( info<0>{-1} ); + auto load = leaf::on_error( info<0>{-1} ); throw leaf::exception( std::exception(), info<1>{-1} ); } void f1() { - auto load = leaf::accumulate( []( info<0> & x ) { }, []( info<1> & x ) { ++x.value; }, []( info<2> & x ) { ++x.value; } ); + auto load = leaf::on_error( []( info<0> & x ) { }, []( info<1> & x ) { ++x.value; }, []( info<2> & x ) { ++x.value; } ); try { f0(); } catch(...) { } throw leaf::exception(std::exception()); } diff --git a/test/accumulate_nested_new_error_result_test.cpp b/test/accumulate_nested_new_error_result_test.cpp index b1e7c89..11d0734 100644 --- a/test/accumulate_nested_new_error_result_test.cpp +++ b/test/accumulate_nested_new_error_result_test.cpp @@ -3,7 +3,7 @@ // 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 #include #include "lightweight_test.hpp" @@ -18,13 +18,13 @@ struct info leaf::error_id f0() { - auto load = leaf::preload( info<0>{-1} ); + auto load = leaf::on_error( info<0>{-1} ); return leaf::new_error( info<1>{-1} ); } leaf::error_id f1() { - auto load = leaf::accumulate( []( info<0> & x ) { }, []( info<1> & x ) { ++x.value; }, []( info<2> & x ) { ++x.value; } ); + auto load = leaf::on_error( []( info<0> & x ) { }, []( info<1> & x ) { ++x.value; }, []( info<2> & x ) { ++x.value; } ); (void) f0(); return leaf::new_error(); } diff --git a/test/accumulate_nested_success_exception_test.cpp b/test/accumulate_nested_success_exception_test.cpp index 90ca2cf..705f5b2 100644 --- a/test/accumulate_nested_success_exception_test.cpp +++ b/test/accumulate_nested_success_exception_test.cpp @@ -16,7 +16,7 @@ int main() #else -#include +#include #include #include "lightweight_test.hpp" @@ -26,7 +26,7 @@ struct info { int value; }; void g1() { - auto load = leaf::accumulate( []( info & x ) { ++x.value; } ); + auto load = leaf::on_error( []( info & x ) { ++x.value; } ); } void g2() @@ -36,7 +36,7 @@ void g2() void f() { - auto load = leaf::preload( info{42} ); + auto load = leaf::on_error( info{42} ); g1(); g2(); } diff --git a/test/accumulate_nested_success_result_test.cpp b/test/accumulate_nested_success_result_test.cpp index 4bac5f1..2e949cd 100644 --- a/test/accumulate_nested_success_result_test.cpp +++ b/test/accumulate_nested_success_result_test.cpp @@ -3,7 +3,7 @@ // 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 #include #include "lightweight_test.hpp" @@ -14,7 +14,7 @@ struct info { int value; }; leaf::result g1() { - auto load = leaf::accumulate( []( info & x ) { ++x.value; } ); + auto load = leaf::on_error( []( info & x ) { ++x.value; } ); return { }; } @@ -25,7 +25,7 @@ leaf::result g2() leaf::result f() { - auto load = leaf::preload( info{2} ); + auto load = leaf::on_error( info{2} ); LEAF_CHECK(g1()); return g2(); } diff --git a/test/capture_exception_async_test.cpp b/test/capture_exception_async_test.cpp index b13fed5..9c6e53e 100644 --- a/test/capture_exception_async_test.cpp +++ b/test/capture_exception_async_test.cpp @@ -19,7 +19,7 @@ int main() #include #include #include -#include +#include #include "lightweight_test.hpp" #include #include @@ -92,7 +92,7 @@ int main() int r = leaf::remote_try_catch( [&] { - auto propagate = leaf::preload( info<4>{} ); + auto propagate = leaf::on_error( info<4>{} ); // Calling future_get is required in order to make the preload (above) work. return leaf::future_get(f.fut); @@ -125,7 +125,7 @@ int main() int r = leaf::remote_try_catch( [&] { - auto propagate = leaf::preload( info<4>{} ); + auto propagate = leaf::on_error( info<4>{} ); return leaf::try_catch( [&] diff --git a/test/capture_exception_result_async_test.cpp b/test/capture_exception_result_async_test.cpp index d237f25..45a2e1b 100644 --- a/test/capture_exception_result_async_test.cpp +++ b/test/capture_exception_result_async_test.cpp @@ -92,7 +92,7 @@ int main() int r = leaf::remote_try_handle_all( [&] { - auto propagate = leaf::preload( info<4>{} ); + auto propagate = leaf::on_error( info<4>{} ); // Calling future_get is required in order to make the preload (above) work. return leaf::future_get(f.fut); @@ -125,7 +125,7 @@ int main() int r = leaf::remote_try_handle_all( [&] { - auto propagate = leaf::preload( info<4>{} ); + auto propagate = leaf::on_error( info<4>{} ); return leaf::try_handle_some( [&] diff --git a/test/capture_exception_unload_test.cpp b/test/capture_exception_unload_test.cpp index 841eb58..b671c7a 100644 --- a/test/capture_exception_unload_test.cpp +++ b/test/capture_exception_unload_test.cpp @@ -19,7 +19,7 @@ int main() #include #include #include -#include +#include #include "lightweight_test.hpp" namespace leaf = boost::leaf; @@ -193,13 +193,13 @@ int main() test, info<2>, info<3>>( [] { - auto load = leaf::preload( info<1>{1}, info<3>{3} ); + auto load = leaf::on_error( info<1>{1}, info<3>{3} ); throw leaf::exception(std::exception()); // Derives from leaf::leaf::error_id } ); test, info<2>, info<3>>( [] { - auto load = leaf::preload( info<1>{1}, info<3>{3} ); + auto load = leaf::on_error( info<1>{1}, info<3>{3} ); throw std::exception(); // Does not derive from leaf::leaf::error_id } ); return boost::report_errors(); diff --git a/test/capture_result_async_test.cpp b/test/capture_result_async_test.cpp index 1dd3a01..4e13a3c 100644 --- a/test/capture_result_async_test.cpp +++ b/test/capture_result_async_test.cpp @@ -19,7 +19,7 @@ int main() #include #include #include -#include +#include #include "lightweight_test.hpp" #include #include @@ -92,7 +92,7 @@ int main() int r = leaf::remote_try_handle_all( [&] { - auto propagate = leaf::preload( info<4>{} ); + auto propagate = leaf::on_error( info<4>{} ); // Calling future_get is required in order to make the preload (above) work. return leaf::future_get(f.fut); @@ -125,7 +125,7 @@ int main() int r = leaf::remote_try_handle_all( [&] { - auto propagate = leaf::preload( info<4>{} ); + auto propagate = leaf::on_error( info<4>{} ); return leaf::try_handle_some( [&] diff --git a/test/defer_basic_test.cpp b/test/defer_basic_test.cpp index 4d9bccd..1af4457 100644 --- a/test/defer_basic_test.cpp +++ b/test/defer_basic_test.cpp @@ -3,7 +3,7 @@ // 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 #include #include "lightweight_test.hpp" @@ -26,7 +26,7 @@ struct info leaf::error_id g() { global = 0; - auto load = leaf::defer( []{ return info<42>{get_global()}; }, []{ return info<-42>{-42}; } ); + auto load = leaf::on_error( []{ return info<42>{get_global()}; }, []{ return info<-42>{-42}; } ); global = 42; return leaf::new_error(); } diff --git a/test/defer_nested_error_exception_test.cpp b/test/defer_nested_error_exception_test.cpp index 9c9d128..9c9a86a 100644 --- a/test/defer_nested_error_exception_test.cpp +++ b/test/defer_nested_error_exception_test.cpp @@ -16,7 +16,7 @@ int main() #else -#include +#include #include #include #include "lightweight_test.hpp" @@ -31,13 +31,13 @@ struct info void f0() { - auto load = leaf::defer( [] { return info<0>{0}; } ); + auto load = leaf::on_error( [] { return info<0>{0}; } ); throw leaf::exception(std::exception(), info<2>{2} ); } void f1() { - auto load = leaf::defer( [] { return info<0>{-1}; }, [] { return info<1>{1}; }, [] { return info<2>{-1}; } ); + auto load = leaf::on_error( [] { return info<0>{-1}; }, [] { return info<1>{1}; }, [] { return info<2>{-1}; } ); f0(); } diff --git a/test/defer_nested_error_result_test.cpp b/test/defer_nested_error_result_test.cpp index de73ae7..b9289bc 100644 --- a/test/defer_nested_error_result_test.cpp +++ b/test/defer_nested_error_result_test.cpp @@ -3,7 +3,7 @@ // 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 #include #include "lightweight_test.hpp" @@ -18,13 +18,13 @@ struct info leaf::error_id f0() { - auto load = leaf::defer( [] { return info<0>{0}; } ); + auto load = leaf::on_error( [] { return info<0>{0}; } ); return leaf::new_error( info<2>{2} ); } leaf::error_id f1() { - auto load = leaf::defer( [] { return info<0>{-1}; }, [] { return info<1>{1}; }, [] { return info<2>{-1}; } ); + auto load = leaf::on_error( [] { return info<0>{-1}; }, [] { return info<1>{1}; }, [] { return info<2>{-1}; } ); return f0(); } diff --git a/test/defer_nested_new_error_exception_test.cpp b/test/defer_nested_new_error_exception_test.cpp index 8778aea..f1640e9 100644 --- a/test/defer_nested_new_error_exception_test.cpp +++ b/test/defer_nested_new_error_exception_test.cpp @@ -16,7 +16,7 @@ int main() #else -#include +#include #include #include #include "lightweight_test.hpp" @@ -31,13 +31,13 @@ struct info void f0() { - auto load = leaf::defer( [] { return info<0>{-1}; } ); + auto load = leaf::on_error( [] { return info<0>{-1}; } ); throw leaf::exception( std::exception(), info<1>{-1} ); } void f1() { - auto load = leaf::defer( [] { return info<0>{0}; }, [] { return info<1>{1}; }, [] { return info<2>{2}; } ); + auto load = leaf::on_error( [] { return info<0>{0}; }, [] { return info<1>{1}; }, [] { return info<2>{2}; } ); try { f0(); } catch(...) { } throw leaf::exception(std::exception()); } diff --git a/test/defer_nested_new_error_result_test.cpp b/test/defer_nested_new_error_result_test.cpp index dc148a0..8d5e9b3 100644 --- a/test/defer_nested_new_error_result_test.cpp +++ b/test/defer_nested_new_error_result_test.cpp @@ -3,7 +3,7 @@ // 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 #include #include "lightweight_test.hpp" @@ -18,13 +18,13 @@ struct info leaf::error_id f0() { - auto load = leaf::defer( [] { return info<0>{-1}; } ); + auto load = leaf::on_error( [] { return info<0>{-1}; } ); return leaf::new_error( info<1>{-1} ); } leaf::error_id f1() { - auto load = leaf::defer( [] { return info<0>{0}; }, [] { return info<1>{1}; }, [] { return info<2>{2}; } ); + auto load = leaf::on_error( [] { return info<0>{0}; }, [] { return info<1>{1}; }, [] { return info<2>{2}; } ); (void) f0(); return leaf::new_error(); } diff --git a/test/defer_nested_success_exception_test.cpp b/test/defer_nested_success_exception_test.cpp index 64d388c..81c983d 100644 --- a/test/defer_nested_success_exception_test.cpp +++ b/test/defer_nested_success_exception_test.cpp @@ -16,7 +16,7 @@ int main() #else -#include +#include #include #include "lightweight_test.hpp" @@ -26,7 +26,7 @@ struct info { int value; }; void g1() { - auto load = leaf::defer( [] { return info{1}; } ); + auto load = leaf::on_error( [] { return info{1}; } ); } void g2() @@ -36,7 +36,7 @@ void g2() void f() { - auto load = leaf::defer( [] { return info{2}; } ); + auto load = leaf::on_error( [] { return info{2}; } ); g1(); g2(); } diff --git a/test/defer_nested_success_result_test.cpp b/test/defer_nested_success_result_test.cpp index 893fc38..1db1f8c 100644 --- a/test/defer_nested_success_result_test.cpp +++ b/test/defer_nested_success_result_test.cpp @@ -3,7 +3,7 @@ // 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 #include #include "lightweight_test.hpp" @@ -14,7 +14,7 @@ struct info { int value; }; leaf::result g1() { - auto load = leaf::defer( [] { return info{1}; } ); + auto load = leaf::on_error( [] { return info{1}; } ); return { }; } @@ -25,7 +25,7 @@ leaf::result g2() leaf::result f() { - auto load = leaf::defer( [] { return info{2}; } ); + auto load = leaf::on_error( [] { return info{2}; } ); LEAF_CHECK(g1()); return g2(); } diff --git a/test/exception_test.cpp b/test/exception_test.cpp index 985a199..03c9961 100644 --- a/test/exception_test.cpp +++ b/test/exception_test.cpp @@ -18,7 +18,7 @@ int main() #include #include -#include +#include #include "lightweight_test.hpp" namespace leaf = boost::leaf; @@ -86,7 +86,7 @@ int main() int const id = leaf::leaf_detail::current_id(); BOOST_TEST_EQ( 3, test( [] { - auto load = leaf::preload(info{42}); + auto load = leaf::on_error(info{42}); throw my_error(); } ) ); BOOST_TEST_NE(id, leaf::leaf_detail::current_id()); diff --git a/test/preload_basic_test.cpp b/test/preload_basic_test.cpp index 3e7b45d..90d013d 100644 --- a/test/preload_basic_test.cpp +++ b/test/preload_basic_test.cpp @@ -3,7 +3,7 @@ // 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 #include #include "lightweight_test.hpp" @@ -55,7 +55,7 @@ int main() test( [] { - auto load = leaf::preload( info<42>{42}, info<-42>{-42} ); + auto load = leaf::on_error( info<42>{42}, info<-42>{-42} ); return leaf::new_error(); }); test( @@ -63,14 +63,14 @@ int main() { info<42> inf1{42}; info<-42> const inf2{-42}; - auto load = leaf::preload( inf1, inf2 ); + auto load = leaf::on_error( inf1, inf2 ); return leaf::new_error(); }); test( [] { info<42> inf1{42}; - auto load = leaf::preload( inf1, info<-42>{-42} ); + auto load = leaf::on_error( inf1, info<-42>{-42} ); return leaf::new_error(); }); return boost::report_errors(); diff --git a/test/preload_exception_test.cpp b/test/preload_exception_test.cpp index fa605e5..8444d0e 100644 --- a/test/preload_exception_test.cpp +++ b/test/preload_exception_test.cpp @@ -16,7 +16,7 @@ int main() #else -#include +#include #include #include #include "lightweight_test.hpp" @@ -32,14 +32,14 @@ struct info template void g1( Thrower th ) { - auto load = leaf::preload( info<1>{} ); + auto load = leaf::on_error( info<1>{} ); th(); } template void g2( Thrower th ) { - auto load = leaf::preload( info<2>{} ); + auto load = leaf::on_error( info<2>{} ); th(); } diff --git a/test/preload_nested_error_exception_test.cpp b/test/preload_nested_error_exception_test.cpp index 26f8b0a..00d171a 100644 --- a/test/preload_nested_error_exception_test.cpp +++ b/test/preload_nested_error_exception_test.cpp @@ -16,7 +16,7 @@ int main() #else -#include +#include #include #include #include "lightweight_test.hpp" @@ -31,13 +31,13 @@ struct info void f0() { - auto load = leaf::preload( info<0>{0} ); + auto load = leaf::on_error( info<0>{0} ); throw leaf::exception(std::exception(), info<2>{2} ); } void f1() { - auto load = leaf::preload( info<0>{-1}, info<1>{1}, info<2>{-1} ); + auto load = leaf::on_error( info<0>{-1}, info<1>{1}, info<2>{-1} ); f0(); } diff --git a/test/preload_nested_error_result_test.cpp b/test/preload_nested_error_result_test.cpp index 1b7369a..2f106cd 100644 --- a/test/preload_nested_error_result_test.cpp +++ b/test/preload_nested_error_result_test.cpp @@ -3,7 +3,7 @@ // 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 #include #include "lightweight_test.hpp" @@ -18,13 +18,13 @@ struct info leaf::error_id f0() { - auto load = leaf::preload( info<0>{0} ); + auto load = leaf::on_error( info<0>{0} ); return leaf::new_error( info<2>{2} ); } leaf::error_id f1() { - auto load = leaf::preload( info<0>{-1}, info<1>{1}, info<2>{-1} ); + auto load = leaf::on_error( info<0>{-1}, info<1>{1}, info<2>{-1} ); return f0(); } diff --git a/test/preload_nested_new_error_exception_test.cpp b/test/preload_nested_new_error_exception_test.cpp index d0e15e7..4ccd273 100644 --- a/test/preload_nested_new_error_exception_test.cpp +++ b/test/preload_nested_new_error_exception_test.cpp @@ -16,7 +16,7 @@ int main() #else -#include +#include #include #include #include "lightweight_test.hpp" @@ -31,13 +31,13 @@ struct info void f0() { - auto load = leaf::preload( info<0>{-1} ); + auto load = leaf::on_error( info<0>{-1} ); throw leaf::exception( std::exception(), info<1>{-1} ); } void f1() { - auto load = leaf::preload( info<0>{0}, info<1>{1}, info<2>{2} ); + auto load = leaf::on_error( info<0>{0}, info<1>{1}, info<2>{2} ); try { f0(); } catch(...) { } throw leaf::exception(std::exception()); } diff --git a/test/preload_nested_new_error_result_test.cpp b/test/preload_nested_new_error_result_test.cpp index 29a6349..dcb2935 100644 --- a/test/preload_nested_new_error_result_test.cpp +++ b/test/preload_nested_new_error_result_test.cpp @@ -3,7 +3,7 @@ // 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 #include #include "lightweight_test.hpp" @@ -18,13 +18,13 @@ struct info leaf::error_id f0() { - auto load = leaf::preload( info<0>{-1} ); + auto load = leaf::on_error( info<0>{-1} ); return leaf::new_error( info<1>{-1} ); } leaf::error_id f1() { - auto load = leaf::preload( info<0>{0}, info<1>{1}, info<2>{2} ); + auto load = leaf::on_error( info<0>{0}, info<1>{1}, info<2>{2} ); (void) f0(); return leaf::new_error(); } diff --git a/test/preload_nested_success_exception_test.cpp b/test/preload_nested_success_exception_test.cpp index cd54efa..cdd99dd 100644 --- a/test/preload_nested_success_exception_test.cpp +++ b/test/preload_nested_success_exception_test.cpp @@ -16,7 +16,7 @@ int main() #else -#include +#include #include #include "lightweight_test.hpp" @@ -26,7 +26,7 @@ struct info { int value; }; void g1() { - auto load = leaf::preload( info{1} ); + auto load = leaf::on_error( info{1} ); } void g2() @@ -36,7 +36,7 @@ void g2() void f() { - auto load = leaf::preload( info{2} ); + auto load = leaf::on_error( info{2} ); g1(); g2(); } diff --git a/test/preload_nested_success_result_test.cpp b/test/preload_nested_success_result_test.cpp index f5901d8..7ee3932 100644 --- a/test/preload_nested_success_result_test.cpp +++ b/test/preload_nested_success_result_test.cpp @@ -3,7 +3,7 @@ // 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 #include #include "lightweight_test.hpp" @@ -14,7 +14,7 @@ struct info { int value; }; leaf::result g1() { - auto load = leaf::preload( info{1} ); + auto load = leaf::on_error( info{1} ); return { }; } @@ -25,7 +25,7 @@ leaf::result g2() leaf::result f() { - auto load = leaf::preload( info{2} ); + auto load = leaf::on_error( info{2} ); LEAF_CHECK(g1()); return g2(); } diff --git a/test/result_load_accumulate_test.cpp b/test/result_load_accumulate_test.cpp index 1142b3d..54e6085 100644 --- a/test/result_load_accumulate_test.cpp +++ b/test/result_load_accumulate_test.cpp @@ -17,8 +17,8 @@ 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; }); + 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; } diff --git a/test/try_catch_error_id_test.cpp b/test/try_catch_error_id_test.cpp index e705570..ef6fbd4 100644 --- a/test/try_catch_error_id_test.cpp +++ b/test/try_catch_error_id_test.cpp @@ -18,7 +18,6 @@ int main() #include #include -#include #include "lightweight_test.hpp" namespace leaf = boost::leaf;