diff --git a/include/boost/leaf/all.hpp b/include/boost/leaf/all.hpp index 0d10b98..69f33ed 100644 --- a/include/boost/leaf/all.hpp +++ b/include/boost/leaf/all.hpp @@ -2902,9 +2902,6 @@ namespace boost { namespace leaf { template BOOST_LEAF_CONSTEXPR R handle_error( error_id, H && ... ); - - template - decltype(std::declval()()) try_catch_( TryBlock &&, H && ... ); }; //////////////////////////////////////// @@ -3776,6 +3773,53 @@ namespace boost { namespace leaf { #else + namespace leaf_detail + { + template + decltype(std::declval()()) + try_catch_( Ctx & ctx, TryBlock && try_block, H && ... h ) + { + using namespace leaf_detail; + BOOST_LEAF_ASSERT(ctx.is_active()); + using R = decltype(std::declval()()); + try + { + return std::forward(try_block)(); + } + catch( capturing_exception const & cap ) + { + try + { + cap.unload_and_rethrow_original_exception(); + } + catch( std::exception & ex ) + { + ctx.deactivate(); + return handle_error_(ctx.tup(), error_info(&ex), std::forward(h)..., + []() -> R { throw; } ); + } + catch(...) + { + ctx.deactivate(); + return handle_error_(ctx.tup(), error_info(nullptr), std::forward(h)..., + []() -> R { throw; } ); + } + } + catch( std::exception & ex ) + { + ctx.deactivate(); + return handle_error_(ctx.tup(), error_info(&ex), std::forward(h)..., + []() -> R { throw; } ); + } + catch(...) + { + ctx.deactivate(); + return handle_error_(ctx.tup(), error_info(nullptr), std::forward(h)..., + []() -> R { throw; } ); + } + } + } + template BOOST_LEAF_CONSTEXPR inline typename std::decay()().value())>::type @@ -3785,7 +3829,8 @@ namespace boost { namespace leaf { context_type_from_handlers ctx; static_assert(is_result_type()())>::value, "The return type of the try_block passed to a try_handle_all function must be registered with leaf::is_result_type"); auto active_context = activate_context(ctx); - if( auto r = ctx.try_catch_( + if( auto r = leaf_detail::try_catch_( + ctx, [&] { return std::forward(try_block)(); @@ -3811,7 +3856,8 @@ namespace boost { namespace leaf { context_type_from_handlers ctx; static_assert(is_result_type()())>::value, "The return type of the try_block passed to a try_handle_some function must be registered with leaf::is_result_type"); auto active_context = activate_context(ctx); - if( auto r = ctx.try_catch_( + if( auto r = leaf_detail::try_catch_( + ctx, [&] { return std::forward(try_block)(); @@ -3831,53 +3877,6 @@ namespace boost { namespace leaf { } } - template - template - inline - decltype(std::declval()()) - context:: - try_catch_( TryBlock && try_block, H && ... h ) - { - using namespace leaf_detail; - BOOST_LEAF_ASSERT(is_active()); - using R = decltype(std::declval()()); - try - { - return std::forward(try_block)(); - } - catch( capturing_exception const & cap ) - { - try - { - cap.unload_and_rethrow_original_exception(); - } - catch( std::exception & ex ) - { - deactivate(); - return handle_error_(this->tup(), error_info(&ex), std::forward(h)..., - []() -> R { throw; } ); - } - catch(...) - { - deactivate(); - return handle_error_(this->tup(), error_info(nullptr), std::forward(h)..., - []() -> R { throw; } ); - } - } - catch( std::exception & ex ) - { - deactivate(); - return handle_error_(this->tup(), error_info(&ex), std::forward(h)..., - []() -> R { throw; } ); - } - catch(...) - { - deactivate(); - return handle_error_(this->tup(), error_info(nullptr), std::forward(h)..., - []() -> R { throw; } ); - } - } - template BOOST_LEAF_CONSTEXPR inline decltype(std::declval()()) @@ -3886,7 +3885,8 @@ namespace boost { namespace leaf { using namespace leaf_detail; context_type_from_handlers ctx; auto active_context = activate_context(ctx); - return ctx.try_catch_( + return leaf_detail::try_catch_( + ctx, [&] { return std::forward(try_block)(); diff --git a/include/boost/leaf/context.hpp b/include/boost/leaf/context.hpp index e43a5a8..42641a5 100644 --- a/include/boost/leaf/context.hpp +++ b/include/boost/leaf/context.hpp @@ -248,9 +248,6 @@ namespace boost { namespace leaf { template BOOST_LEAF_CONSTEXPR R handle_error( error_id, H && ... ); - - template - decltype(std::declval()()) try_catch_( TryBlock &&, H && ... ); }; //////////////////////////////////////// diff --git a/include/boost/leaf/handle_errors.hpp b/include/boost/leaf/handle_errors.hpp index ae71129..a899ece 100644 --- a/include/boost/leaf/handle_errors.hpp +++ b/include/boost/leaf/handle_errors.hpp @@ -650,6 +650,53 @@ namespace boost { namespace leaf { #else + namespace leaf_detail + { + template + decltype(std::declval()()) + try_catch_( Ctx & ctx, TryBlock && try_block, H && ... h ) + { + using namespace leaf_detail; + BOOST_LEAF_ASSERT(ctx.is_active()); + using R = decltype(std::declval()()); + try + { + return std::forward(try_block)(); + } + catch( capturing_exception const & cap ) + { + try + { + cap.unload_and_rethrow_original_exception(); + } + catch( std::exception & ex ) + { + ctx.deactivate(); + return handle_error_(ctx.tup(), error_info(&ex), std::forward(h)..., + []() -> R { throw; } ); + } + catch(...) + { + ctx.deactivate(); + return handle_error_(ctx.tup(), error_info(nullptr), std::forward(h)..., + []() -> R { throw; } ); + } + } + catch( std::exception & ex ) + { + ctx.deactivate(); + return handle_error_(ctx.tup(), error_info(&ex), std::forward(h)..., + []() -> R { throw; } ); + } + catch(...) + { + ctx.deactivate(); + return handle_error_(ctx.tup(), error_info(nullptr), std::forward(h)..., + []() -> R { throw; } ); + } + } + } + template BOOST_LEAF_CONSTEXPR inline typename std::decay()().value())>::type @@ -659,7 +706,8 @@ namespace boost { namespace leaf { context_type_from_handlers ctx; static_assert(is_result_type()())>::value, "The return type of the try_block passed to a try_handle_all function must be registered with leaf::is_result_type"); auto active_context = activate_context(ctx); - if( auto r = ctx.try_catch_( + if( auto r = leaf_detail::try_catch_( + ctx, [&] { return std::forward(try_block)(); @@ -685,7 +733,8 @@ namespace boost { namespace leaf { context_type_from_handlers ctx; static_assert(is_result_type()())>::value, "The return type of the try_block passed to a try_handle_some function must be registered with leaf::is_result_type"); auto active_context = activate_context(ctx); - if( auto r = ctx.try_catch_( + if( auto r = leaf_detail::try_catch_( + ctx, [&] { return std::forward(try_block)(); @@ -705,53 +754,6 @@ namespace boost { namespace leaf { } } - template - template - inline - decltype(std::declval()()) - context:: - try_catch_( TryBlock && try_block, H && ... h ) - { - using namespace leaf_detail; - BOOST_LEAF_ASSERT(is_active()); - using R = decltype(std::declval()()); - try - { - return std::forward(try_block)(); - } - catch( capturing_exception const & cap ) - { - try - { - cap.unload_and_rethrow_original_exception(); - } - catch( std::exception & ex ) - { - deactivate(); - return handle_error_(this->tup(), error_info(&ex), std::forward(h)..., - []() -> R { throw; } ); - } - catch(...) - { - deactivate(); - return handle_error_(this->tup(), error_info(nullptr), std::forward(h)..., - []() -> R { throw; } ); - } - } - catch( std::exception & ex ) - { - deactivate(); - return handle_error_(this->tup(), error_info(&ex), std::forward(h)..., - []() -> R { throw; } ); - } - catch(...) - { - deactivate(); - return handle_error_(this->tup(), error_info(nullptr), std::forward(h)..., - []() -> R { throw; } ); - } - } - template BOOST_LEAF_CONSTEXPR inline decltype(std::declval()()) @@ -760,7 +762,8 @@ namespace boost { namespace leaf { using namespace leaf_detail; context_type_from_handlers ctx; auto active_context = activate_context(ctx); - return ctx.try_catch_( + return leaf_detail::try_catch_( + ctx, [&] { return std::forward(try_block)();