2
0
mirror of https://github.com/boostorg/leaf.git synced 2026-01-31 08:12:26 +00:00

Made context::try_catch_ a namespace-scope function

This commit is contained in:
unknown
2020-07-08 22:52:15 -07:00
parent 6eb228eb4e
commit 061da7e810
3 changed files with 106 additions and 106 deletions

View File

@@ -2902,9 +2902,6 @@ namespace boost { namespace leaf {
template <class R, class... H>
BOOST_LEAF_CONSTEXPR R handle_error( error_id, H && ... );
template <class TryBlock, class... H>
decltype(std::declval<TryBlock>()()) try_catch_( TryBlock &&, H && ... );
};
////////////////////////////////////////
@@ -3776,6 +3773,53 @@ namespace boost { namespace leaf {
#else
namespace leaf_detail
{
template <class Ctx, class TryBlock, class... H>
decltype(std::declval<TryBlock>()())
try_catch_( Ctx & ctx, TryBlock && try_block, H && ... h )
{
using namespace leaf_detail;
BOOST_LEAF_ASSERT(ctx.is_active());
using R = decltype(std::declval<TryBlock>()());
try
{
return std::forward<TryBlock>(try_block)();
}
catch( capturing_exception const & cap )
{
try
{
cap.unload_and_rethrow_original_exception();
}
catch( std::exception & ex )
{
ctx.deactivate();
return handle_error_<R>(ctx.tup(), error_info(&ex), std::forward<H>(h)...,
[]() -> R { throw; } );
}
catch(...)
{
ctx.deactivate();
return handle_error_<R>(ctx.tup(), error_info(nullptr), std::forward<H>(h)...,
[]() -> R { throw; } );
}
}
catch( std::exception & ex )
{
ctx.deactivate();
return handle_error_<R>(ctx.tup(), error_info(&ex), std::forward<H>(h)...,
[]() -> R { throw; } );
}
catch(...)
{
ctx.deactivate();
return handle_error_<R>(ctx.tup(), error_info(nullptr), std::forward<H>(h)...,
[]() -> R { throw; } );
}
}
}
template <class TryBlock, class... H>
BOOST_LEAF_CONSTEXPR inline
typename std::decay<decltype(std::declval<TryBlock>()().value())>::type
@@ -3785,7 +3829,8 @@ namespace boost { namespace leaf {
context_type_from_handlers<H...> ctx;
static_assert(is_result_type<decltype(std::declval<TryBlock>()())>::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<TryBlock>(try_block)();
@@ -3811,7 +3856,8 @@ namespace boost { namespace leaf {
context_type_from_handlers<H...> ctx;
static_assert(is_result_type<decltype(std::declval<TryBlock>()())>::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<TryBlock>(try_block)();
@@ -3831,53 +3877,6 @@ namespace boost { namespace leaf {
}
}
template <class... E>
template <class TryBlock, class... H>
inline
decltype(std::declval<TryBlock>()())
context<E...>::
try_catch_( TryBlock && try_block, H && ... h )
{
using namespace leaf_detail;
BOOST_LEAF_ASSERT(is_active());
using R = decltype(std::declval<TryBlock>()());
try
{
return std::forward<TryBlock>(try_block)();
}
catch( capturing_exception const & cap )
{
try
{
cap.unload_and_rethrow_original_exception();
}
catch( std::exception & ex )
{
deactivate();
return handle_error_<R>(this->tup(), error_info(&ex), std::forward<H>(h)...,
[]() -> R { throw; } );
}
catch(...)
{
deactivate();
return handle_error_<R>(this->tup(), error_info(nullptr), std::forward<H>(h)...,
[]() -> R { throw; } );
}
}
catch( std::exception & ex )
{
deactivate();
return handle_error_<R>(this->tup(), error_info(&ex), std::forward<H>(h)...,
[]() -> R { throw; } );
}
catch(...)
{
deactivate();
return handle_error_<R>(this->tup(), error_info(nullptr), std::forward<H>(h)...,
[]() -> R { throw; } );
}
}
template <class TryBlock, class... H>
BOOST_LEAF_CONSTEXPR inline
decltype(std::declval<TryBlock>()())
@@ -3886,7 +3885,8 @@ namespace boost { namespace leaf {
using namespace leaf_detail;
context_type_from_handlers<H...> ctx;
auto active_context = activate_context(ctx);
return ctx.try_catch_(
return leaf_detail::try_catch_(
ctx,
[&]
{
return std::forward<TryBlock>(try_block)();

View File

@@ -248,9 +248,6 @@ namespace boost { namespace leaf {
template <class R, class... H>
BOOST_LEAF_CONSTEXPR R handle_error( error_id, H && ... );
template <class TryBlock, class... H>
decltype(std::declval<TryBlock>()()) try_catch_( TryBlock &&, H && ... );
};
////////////////////////////////////////

View File

@@ -650,6 +650,53 @@ namespace boost { namespace leaf {
#else
namespace leaf_detail
{
template <class Ctx, class TryBlock, class... H>
decltype(std::declval<TryBlock>()())
try_catch_( Ctx & ctx, TryBlock && try_block, H && ... h )
{
using namespace leaf_detail;
BOOST_LEAF_ASSERT(ctx.is_active());
using R = decltype(std::declval<TryBlock>()());
try
{
return std::forward<TryBlock>(try_block)();
}
catch( capturing_exception const & cap )
{
try
{
cap.unload_and_rethrow_original_exception();
}
catch( std::exception & ex )
{
ctx.deactivate();
return handle_error_<R>(ctx.tup(), error_info(&ex), std::forward<H>(h)...,
[]() -> R { throw; } );
}
catch(...)
{
ctx.deactivate();
return handle_error_<R>(ctx.tup(), error_info(nullptr), std::forward<H>(h)...,
[]() -> R { throw; } );
}
}
catch( std::exception & ex )
{
ctx.deactivate();
return handle_error_<R>(ctx.tup(), error_info(&ex), std::forward<H>(h)...,
[]() -> R { throw; } );
}
catch(...)
{
ctx.deactivate();
return handle_error_<R>(ctx.tup(), error_info(nullptr), std::forward<H>(h)...,
[]() -> R { throw; } );
}
}
}
template <class TryBlock, class... H>
BOOST_LEAF_CONSTEXPR inline
typename std::decay<decltype(std::declval<TryBlock>()().value())>::type
@@ -659,7 +706,8 @@ namespace boost { namespace leaf {
context_type_from_handlers<H...> ctx;
static_assert(is_result_type<decltype(std::declval<TryBlock>()())>::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<TryBlock>(try_block)();
@@ -685,7 +733,8 @@ namespace boost { namespace leaf {
context_type_from_handlers<H...> ctx;
static_assert(is_result_type<decltype(std::declval<TryBlock>()())>::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<TryBlock>(try_block)();
@@ -705,53 +754,6 @@ namespace boost { namespace leaf {
}
}
template <class... E>
template <class TryBlock, class... H>
inline
decltype(std::declval<TryBlock>()())
context<E...>::
try_catch_( TryBlock && try_block, H && ... h )
{
using namespace leaf_detail;
BOOST_LEAF_ASSERT(is_active());
using R = decltype(std::declval<TryBlock>()());
try
{
return std::forward<TryBlock>(try_block)();
}
catch( capturing_exception const & cap )
{
try
{
cap.unload_and_rethrow_original_exception();
}
catch( std::exception & ex )
{
deactivate();
return handle_error_<R>(this->tup(), error_info(&ex), std::forward<H>(h)...,
[]() -> R { throw; } );
}
catch(...)
{
deactivate();
return handle_error_<R>(this->tup(), error_info(nullptr), std::forward<H>(h)...,
[]() -> R { throw; } );
}
}
catch( std::exception & ex )
{
deactivate();
return handle_error_<R>(this->tup(), error_info(&ex), std::forward<H>(h)...,
[]() -> R { throw; } );
}
catch(...)
{
deactivate();
return handle_error_<R>(this->tup(), error_info(nullptr), std::forward<H>(h)...,
[]() -> R { throw; } );
}
}
template <class TryBlock, class... H>
BOOST_LEAF_CONSTEXPR inline
decltype(std::declval<TryBlock>()())
@@ -760,7 +762,8 @@ namespace boost { namespace leaf {
using namespace leaf_detail;
context_type_from_handlers<H...> ctx;
auto active_context = activate_context(ctx);
return ctx.try_catch_(
return leaf_detail::try_catch_(
ctx,
[&]
{
return std::forward<TryBlock>(try_block)();