diff --git a/examples/asio_beast_leaf_rpc.cpp b/examples/asio_beast_leaf_rpc.cpp index 673ef50..39921c3 100644 --- a/examples/asio_beast_leaf_rpc.cpp +++ b/examples/asio_beast_leaf_rpc.cpp @@ -124,7 +124,7 @@ auto async_demo_rpc(AsyncStream &stream, ErrorContext &error_context, Completion void operator()(error_code ec, std::size_t /*bytes_transferred*/ = 0) { leaf::result result_continue_execution; { - leaf::context_activator active_context{m_error_context, leaf::on_deactivation::do_not_propagate}; + auto active_context = activate_context(m_error_context, leaf::on_deactivation::do_not_propagate); auto load = leaf::preload(e_last_operation{m_data.response ? "async_demo_rpc::continuation-write" : "async_demo_rpc::continuation-read"}); if (ec == http::error::end_of_stream) { @@ -539,10 +539,7 @@ int main(int argc, char **argv) { async_demo_rpc(socket, error_context, [&](leaf::result result) { // Note: In case we wanted to add some additional information to the error associated with the result // we would need to activate the error-context - // In this example this is not the case, so the next line is commented out. - // leaf::context_activator<> active_context(error_context, leaf::on_deactivation::do_not_propagate); - - leaf::context_activator active_context(error_context, leaf::on_deactivation::do_not_propagate); + auto active_context = activate_context(error_context, leaf::on_deactivation::do_not_propagate); if (result) { std::cout << "Server: Client work completed successfully" << std::endl; rv = 0; diff --git a/include/boost/leaf/all.hpp b/include/boost/leaf/all.hpp index fd7643d..6a0c06f 100644 --- a/include/boost/leaf/all.hpp +++ b/include/boost/leaf/all.hpp @@ -1554,29 +1554,19 @@ namespace boost { namespace leaf { propagate_if_uncaught_exception }; + template class context_activator { context_activator( context_activator const & ) = delete; context_activator & operator=( context_activator const & ) = delete; - void (* const deactivate_)(context_activator *, bool) noexcept; - void * const ctx_; + Ctx * ctx_; bool const ctx_was_active_; on_deactivation on_deactivate_; - template - static void deactivate_fwd(context_activator * this_, bool propagate_errors) noexcept - { - assert(this_->deactivate_!=0); - assert(this_->ctx_!=0); - static_cast(this_->ctx_)->deactivate(propagate_errors); - } - public: - template context_activator(Ctx & ctx, on_deactivation on_deactivate) noexcept: - deactivate_(&deactivate_fwd), ctx_(&ctx), ctx_was_active_(ctx.is_active()), on_deactivate_(on_deactivate) @@ -1585,26 +1575,37 @@ namespace boost { namespace leaf { ctx.activate(); } + context_activator( context_activator && x ) noexcept: + ctx_(x.ctx_), + ctx_was_active_(x.ctx_was_active_), + on_deactivate_(x.on_deactivate_) + { + x.ctx_ = 0; + } + ~context_activator() noexcept { - assert( - on_deactivate_ == on_deactivation::propagate || - on_deactivate_ == on_deactivation::do_not_propagate || - on_deactivate_ == on_deactivation::propagate_if_uncaught_exception); - if( !ctx_was_active_ ) - if( on_deactivate_ == on_deactivation::propagate_if_uncaught_exception ) - { + if( ctx_ ) + { + assert( + on_deactivate_ == on_deactivation::propagate || + on_deactivate_ == on_deactivation::do_not_propagate || + on_deactivate_ == on_deactivation::propagate_if_uncaught_exception); + if( !ctx_was_active_ ) + if( on_deactivate_ == on_deactivation::propagate_if_uncaught_exception ) + { #ifdef LEAF_NO_EXCEPTIONS - deactivate_(this, false); + ctx_->deactivate(false); #else - bool has_exception = std::uncaught_exception(); - deactivate_(this, has_exception); - if( !has_exception ) - (void) leaf_detail::new_id(); + bool has_exception = std::uncaught_exception(); + ctx_->deactivate(has_exception); + if( !has_exception ) + (void) leaf_detail::new_id(); #endif - } - else - deactivate_(this, on_deactivate_ == on_deactivation::propagate); + } + else + ctx_->deactivate(on_deactivate_ == on_deactivation::propagate); + } } void set_on_deactivate( on_deactivation on_deactivate ) noexcept @@ -1613,6 +1614,12 @@ namespace boost { namespace leaf { } }; + template + context_activator activate_context( Ctx & ctx, on_deactivation on_deactivate ) noexcept + { + return context_activator(ctx, on_deactivate); + } + //////////////////////////////////////////// template @@ -1753,7 +1760,7 @@ namespace boost { namespace leaf { [[noreturn]] void unload_and_rethrow_original_exception() const { - context_activator active_context(*ctx_, on_deactivation::propagate); + auto active_context = activate_context(*ctx_, on_deactivation::propagate); std::rethrow_exception(ex_); } @@ -1766,7 +1773,7 @@ namespace boost { namespace leaf { template inline decltype(std::declval()(std::forward(std::declval())...)) capture_impl(is_result_tag, context_ptr const & ctx, F && f, A... a) { - context_activator active_context(*ctx, on_deactivation::do_not_propagate); + auto active_context = activate_context(*ctx, on_deactivation::do_not_propagate); try { return std::forward(f)(std::forward(a)...); @@ -1784,7 +1791,7 @@ namespace boost { namespace leaf { template inline decltype(std::declval()(std::forward(std::declval())...)) capture_impl(is_result_tag, context_ptr const & ctx, F && f, A... a) { - context_activator active_context(*ctx, on_deactivation::do_not_propagate); + auto active_context = activate_context(*ctx, on_deactivation::do_not_propagate); try { if( auto r = std::forward(f)(std::forward(a)...) ) @@ -1813,14 +1820,14 @@ namespace boost { namespace leaf { template inline decltype(std::declval()(std::forward(std::declval())...)) capture_impl(is_result_tag, context_ptr const & ctx, F && f, A... a) { - context_activator active_context(*ctx, on_deactivation::do_not_propagate); + auto active_context = activate_context(*ctx, on_deactivation::do_not_propagate); return std::forward(f)(std::forward(a)...); } template inline decltype(std::declval()(std::forward(std::declval())...)) capture_impl(is_result_tag, context_ptr const & ctx, F && f, A... a) { - context_activator active_context(*ctx, on_deactivation::do_not_propagate); + auto active_context = activate_context(*ctx, on_deactivation::do_not_propagate); if( auto r = std::forward(f)(std::forward(a)...) ) return r; else @@ -2277,11 +2284,11 @@ namespace boost { namespace leaf { template typename std::decay()().value())>::type remote_try_handle_all_( TryBlock &&, RemoteH && ) const; - template - typename std::decay()())>::type try_handle_some_( context_activator &, TryBlock &&, H && ... ) const; + template + typename std::decay()())>::type try_handle_some_( context_activator &, TryBlock &&, H && ... ) const; - template - typename std::decay()())>::type remote_try_handle_some_( context_activator &, TryBlock &&, RemoteH && ) const; + template + typename std::decay()())>::type remote_try_handle_some_( context_activator &, TryBlock &&, RemoteH && ) const; public: @@ -3276,8 +3283,8 @@ namespace boost { namespace leaf { } template - template - inline typename std::decay()())>::type context_base::try_handle_some_( context_activator & active_context, TryBlock && try_block, H && ... h ) const + template + inline typename std::decay()())>::type context_base::try_handle_some_( context_activator & active_context, TryBlock && try_block, H && ... h ) const { using namespace leaf_detail; 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"); @@ -3294,8 +3301,8 @@ namespace boost { namespace leaf { } template - template - inline typename std::decay()())>::type context_base::remote_try_handle_some_( context_activator & active_context, TryBlock && try_block, RemoteH && h ) const + template + inline typename std::decay()())>::type context_base::remote_try_handle_some_( context_activator & active_context, TryBlock && try_block, RemoteH && h ) const { using namespace leaf_detail; static_assert(is_result_type()())>::value, "The return type of the try_block passed to a remote_try_handle_some function must be registered with leaf::is_result_type"); @@ -3411,7 +3418,7 @@ namespace boost { namespace leaf { template inline typename std::decay()().value())>::type nocatch_context::try_handle_all( TryBlock && try_block, H && ... h ) { - context_activator active_context(*this, on_deactivation::do_not_propagate); + auto active_context = activate_context(*this, on_deactivation::do_not_propagate); return this->try_handle_all_( std::forward(try_block), std::forward(h)... ); } @@ -3419,7 +3426,7 @@ namespace boost { namespace leaf { template inline typename std::decay()().value())>::type nocatch_context::remote_try_handle_all( TryBlock && try_block, RemoteH && h ) { - context_activator active_context(*this, on_deactivation::do_not_propagate); + auto active_context = activate_context(*this, on_deactivation::do_not_propagate); return this->remote_try_handle_all_( std::forward(try_block), std::forward(h) ); } @@ -3427,7 +3434,7 @@ namespace boost { namespace leaf { template inline typename std::decay()())>::type nocatch_context::try_handle_some( TryBlock && try_block, H && ... h ) { - context_activator active_context(*this, on_deactivation::propagate_if_uncaught_exception); + auto active_context = activate_context(*this, on_deactivation::propagate_if_uncaught_exception); return this->try_handle_some_( active_context, std::forward(try_block), std::forward(h)... ); } @@ -3435,7 +3442,7 @@ namespace boost { namespace leaf { template inline typename std::decay()())>::type nocatch_context::remote_try_handle_some( TryBlock && try_block, RemoteH && h ) { - context_activator active_context(*this, on_deactivation::propagate_if_uncaught_exception); + auto active_context = activate_context(*this, on_deactivation::propagate_if_uncaught_exception); return this->remote_try_handle_some_( active_context, std::forward(try_block), std::forward(h) ); } } @@ -3693,7 +3700,7 @@ namespace boost { namespace leaf { { using namespace leaf_detail; context_type_from_handlers ctx; - context_activator active_context(ctx, on_deactivation::propagate_if_uncaught_exception); + auto active_context = activate_context(ctx, on_deactivation::propagate_if_uncaught_exception); return ctx.try_catch_( [&] { @@ -3707,7 +3714,7 @@ namespace boost { namespace leaf { { using namespace leaf_detail; context_type_from_remote_handler ctx; - context_activator active_context(ctx, on_deactivation::propagate_if_uncaught_exception); + auto active_context = activate_context(ctx, on_deactivation::propagate_if_uncaught_exception); return ctx.remote_try_catch_( [&] { @@ -3762,7 +3769,7 @@ namespace boost { namespace leaf { { using namespace leaf_detail; 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"); - context_activator active_context(*this, on_deactivation::propagate_if_uncaught_exception); + auto active_context = activate_context(*this, on_deactivation::propagate_if_uncaught_exception); if( auto r = this->try_catch_( [&] { @@ -3780,7 +3787,7 @@ namespace boost { namespace leaf { { using namespace leaf_detail; 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"); - context_activator active_context(*this, on_deactivation::propagate_if_uncaught_exception); + auto active_context = activate_context(*this, on_deactivation::propagate_if_uncaught_exception); if( auto r = this->remote_try_catch_( [&] { @@ -3798,7 +3805,7 @@ namespace boost { namespace leaf { { using namespace leaf_detail; 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"); - context_activator active_context(*this, on_deactivation::propagate_if_uncaught_exception); + auto active_context = activate_context(*this, on_deactivation::propagate_if_uncaught_exception); if( auto r = this->try_catch_( [&] { @@ -3819,7 +3826,7 @@ namespace boost { namespace leaf { template inline typename std::decay()())>::type catch_context::remote_try_handle_some( TryBlock && try_block, RemoteH && h ) { - context_activator active_context(*this, on_deactivation::propagate_if_uncaught_exception); + auto active_context = activate_context(*this, on_deactivation::propagate_if_uncaught_exception); if( auto r = this->remote_try_catch_( [&] { diff --git a/include/boost/leaf/capture.hpp b/include/boost/leaf/capture.hpp index 78b2903..c2c2d56 100644 --- a/include/boost/leaf/capture.hpp +++ b/include/boost/leaf/capture.hpp @@ -33,7 +33,7 @@ namespace boost { namespace leaf { [[noreturn]] void unload_and_rethrow_original_exception() const { - context_activator active_context(*ctx_, on_deactivation::propagate); + auto active_context = activate_context(*ctx_, on_deactivation::propagate); std::rethrow_exception(ex_); } @@ -46,7 +46,7 @@ namespace boost { namespace leaf { template inline decltype(std::declval()(std::forward(std::declval())...)) capture_impl(is_result_tag, context_ptr const & ctx, F && f, A... a) { - context_activator active_context(*ctx, on_deactivation::do_not_propagate); + auto active_context = activate_context(*ctx, on_deactivation::do_not_propagate); try { return std::forward(f)(std::forward(a)...); @@ -64,7 +64,7 @@ namespace boost { namespace leaf { template inline decltype(std::declval()(std::forward(std::declval())...)) capture_impl(is_result_tag, context_ptr const & ctx, F && f, A... a) { - context_activator active_context(*ctx, on_deactivation::do_not_propagate); + auto active_context = activate_context(*ctx, on_deactivation::do_not_propagate); try { if( auto r = std::forward(f)(std::forward(a)...) ) @@ -93,14 +93,14 @@ namespace boost { namespace leaf { template inline decltype(std::declval()(std::forward(std::declval())...)) capture_impl(is_result_tag, context_ptr const & ctx, F && f, A... a) { - context_activator active_context(*ctx, on_deactivation::do_not_propagate); + auto active_context = activate_context(*ctx, on_deactivation::do_not_propagate); return std::forward(f)(std::forward(a)...); } template inline decltype(std::declval()(std::forward(std::declval())...)) capture_impl(is_result_tag, context_ptr const & ctx, F && f, A... a) { - context_activator active_context(*ctx, on_deactivation::do_not_propagate); + auto active_context = activate_context(*ctx, on_deactivation::do_not_propagate); if( auto r = std::forward(f)(std::forward(a)...) ) return r; else diff --git a/include/boost/leaf/context.hpp b/include/boost/leaf/context.hpp index b73e7f4..320f291 100644 --- a/include/boost/leaf/context.hpp +++ b/include/boost/leaf/context.hpp @@ -281,11 +281,11 @@ namespace boost { namespace leaf { template typename std::decay()().value())>::type remote_try_handle_all_( TryBlock &&, RemoteH && ) const; - template - typename std::decay()())>::type try_handle_some_( context_activator &, TryBlock &&, H && ... ) const; + template + typename std::decay()())>::type try_handle_some_( context_activator &, TryBlock &&, H && ... ) const; - template - typename std::decay()())>::type remote_try_handle_some_( context_activator &, TryBlock &&, RemoteH && ) const; + template + typename std::decay()())>::type remote_try_handle_some_( context_activator &, TryBlock &&, RemoteH && ) const; public: diff --git a/include/boost/leaf/detail/handle.hpp b/include/boost/leaf/detail/handle.hpp index 56b2935..390256a 100644 --- a/include/boost/leaf/detail/handle.hpp +++ b/include/boost/leaf/detail/handle.hpp @@ -779,8 +779,8 @@ namespace boost { namespace leaf { } template - template - inline typename std::decay()())>::type context_base::try_handle_some_( context_activator & active_context, TryBlock && try_block, H && ... h ) const + template + inline typename std::decay()())>::type context_base::try_handle_some_( context_activator & active_context, TryBlock && try_block, H && ... h ) const { using namespace leaf_detail; 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"); @@ -797,8 +797,8 @@ namespace boost { namespace leaf { } template - template - inline typename std::decay()())>::type context_base::remote_try_handle_some_( context_activator & active_context, TryBlock && try_block, RemoteH && h ) const + template + inline typename std::decay()())>::type context_base::remote_try_handle_some_( context_activator & active_context, TryBlock && try_block, RemoteH && h ) const { using namespace leaf_detail; static_assert(is_result_type()())>::value, "The return type of the try_block passed to a remote_try_handle_some function must be registered with leaf::is_result_type"); diff --git a/include/boost/leaf/error.hpp b/include/boost/leaf/error.hpp index b9f47e4..c744127 100644 --- a/include/boost/leaf/error.hpp +++ b/include/boost/leaf/error.hpp @@ -806,29 +806,19 @@ namespace boost { namespace leaf { propagate_if_uncaught_exception }; + template class context_activator { context_activator( context_activator const & ) = delete; context_activator & operator=( context_activator const & ) = delete; - void (* const deactivate_)(context_activator *, bool) noexcept; - void * const ctx_; + Ctx * ctx_; bool const ctx_was_active_; on_deactivation on_deactivate_; - template - static void deactivate_fwd(context_activator * this_, bool propagate_errors) noexcept - { - assert(this_->deactivate_!=0); - assert(this_->ctx_!=0); - static_cast(this_->ctx_)->deactivate(propagate_errors); - } - public: - template context_activator(Ctx & ctx, on_deactivation on_deactivate) noexcept: - deactivate_(&deactivate_fwd), ctx_(&ctx), ctx_was_active_(ctx.is_active()), on_deactivate_(on_deactivate) @@ -837,26 +827,37 @@ namespace boost { namespace leaf { ctx.activate(); } + context_activator( context_activator && x ) noexcept: + ctx_(x.ctx_), + ctx_was_active_(x.ctx_was_active_), + on_deactivate_(x.on_deactivate_) + { + x.ctx_ = 0; + } + ~context_activator() noexcept { - assert( - on_deactivate_ == on_deactivation::propagate || - on_deactivate_ == on_deactivation::do_not_propagate || - on_deactivate_ == on_deactivation::propagate_if_uncaught_exception); - if( !ctx_was_active_ ) - if( on_deactivate_ == on_deactivation::propagate_if_uncaught_exception ) - { + if( ctx_ ) + { + assert( + on_deactivate_ == on_deactivation::propagate || + on_deactivate_ == on_deactivation::do_not_propagate || + on_deactivate_ == on_deactivation::propagate_if_uncaught_exception); + if( !ctx_was_active_ ) + if( on_deactivate_ == on_deactivation::propagate_if_uncaught_exception ) + { #ifdef LEAF_NO_EXCEPTIONS - deactivate_(this, false); + ctx_->deactivate(false); #else - bool has_exception = std::uncaught_exception(); - deactivate_(this, has_exception); - if( !has_exception ) - (void) leaf_detail::new_id(); + bool has_exception = std::uncaught_exception(); + ctx_->deactivate(has_exception); + if( !has_exception ) + (void) leaf_detail::new_id(); #endif - } - else - deactivate_(this, on_deactivate_ == on_deactivation::propagate); + } + else + ctx_->deactivate(on_deactivate_ == on_deactivation::propagate); + } } void set_on_deactivate( on_deactivation on_deactivate ) noexcept @@ -865,6 +866,12 @@ namespace boost { namespace leaf { } }; + template + context_activator activate_context( Ctx & ctx, on_deactivation on_deactivate ) noexcept + { + return context_activator(ctx, on_deactivate); + } + //////////////////////////////////////////// template diff --git a/include/boost/leaf/handle_error.hpp b/include/boost/leaf/handle_error.hpp index 177104f..f595c38 100644 --- a/include/boost/leaf/handle_error.hpp +++ b/include/boost/leaf/handle_error.hpp @@ -16,7 +16,7 @@ namespace boost { namespace leaf { template inline typename std::decay()().value())>::type nocatch_context::try_handle_all( TryBlock && try_block, H && ... h ) { - context_activator active_context(*this, on_deactivation::do_not_propagate); + auto active_context = activate_context(*this, on_deactivation::do_not_propagate); return this->try_handle_all_( std::forward(try_block), std::forward(h)... ); } @@ -24,7 +24,7 @@ namespace boost { namespace leaf { template inline typename std::decay()().value())>::type nocatch_context::remote_try_handle_all( TryBlock && try_block, RemoteH && h ) { - context_activator active_context(*this, on_deactivation::do_not_propagate); + auto active_context = activate_context(*this, on_deactivation::do_not_propagate); return this->remote_try_handle_all_( std::forward(try_block), std::forward(h) ); } @@ -32,7 +32,7 @@ namespace boost { namespace leaf { template inline typename std::decay()())>::type nocatch_context::try_handle_some( TryBlock && try_block, H && ... h ) { - context_activator active_context(*this, on_deactivation::propagate_if_uncaught_exception); + auto active_context = activate_context(*this, on_deactivation::propagate_if_uncaught_exception); return this->try_handle_some_( active_context, std::forward(try_block), std::forward(h)... ); } @@ -40,7 +40,7 @@ namespace boost { namespace leaf { template inline typename std::decay()())>::type nocatch_context::remote_try_handle_some( TryBlock && try_block, RemoteH && h ) { - context_activator active_context(*this, on_deactivation::propagate_if_uncaught_exception); + auto active_context = activate_context(*this, on_deactivation::propagate_if_uncaught_exception); return this->remote_try_handle_some_( active_context, std::forward(try_block), std::forward(h) ); } } diff --git a/include/boost/leaf/handle_exception.hpp b/include/boost/leaf/handle_exception.hpp index bf327b9..f2dbd83 100644 --- a/include/boost/leaf/handle_exception.hpp +++ b/include/boost/leaf/handle_exception.hpp @@ -124,7 +124,7 @@ namespace boost { namespace leaf { { using namespace leaf_detail; context_type_from_handlers ctx; - context_activator active_context(ctx, on_deactivation::propagate_if_uncaught_exception); + auto active_context = activate_context(ctx, on_deactivation::propagate_if_uncaught_exception); return ctx.try_catch_( [&] { @@ -138,7 +138,7 @@ namespace boost { namespace leaf { { using namespace leaf_detail; context_type_from_remote_handler ctx; - context_activator active_context(ctx, on_deactivation::propagate_if_uncaught_exception); + auto active_context = activate_context(ctx, on_deactivation::propagate_if_uncaught_exception); return ctx.remote_try_catch_( [&] { @@ -193,7 +193,7 @@ namespace boost { namespace leaf { { using namespace leaf_detail; 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"); - context_activator active_context(*this, on_deactivation::propagate_if_uncaught_exception); + auto active_context = activate_context(*this, on_deactivation::propagate_if_uncaught_exception); if( auto r = this->try_catch_( [&] { @@ -211,7 +211,7 @@ namespace boost { namespace leaf { { using namespace leaf_detail; 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"); - context_activator active_context(*this, on_deactivation::propagate_if_uncaught_exception); + auto active_context = activate_context(*this, on_deactivation::propagate_if_uncaught_exception); if( auto r = this->remote_try_catch_( [&] { @@ -229,7 +229,7 @@ namespace boost { namespace leaf { { using namespace leaf_detail; 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"); - context_activator active_context(*this, on_deactivation::propagate_if_uncaught_exception); + auto active_context = activate_context(*this, on_deactivation::propagate_if_uncaught_exception); if( auto r = this->try_catch_( [&] { @@ -250,7 +250,7 @@ namespace boost { namespace leaf { template inline typename std::decay()())>::type catch_context::remote_try_handle_some( TryBlock && try_block, RemoteH && h ) { - context_activator active_context(*this, on_deactivation::propagate_if_uncaught_exception); + auto active_context = activate_context(*this, on_deactivation::propagate_if_uncaught_exception); if( auto r = this->remote_try_catch_( [&] { diff --git a/test/context_activator_test.cpp b/test/context_activator_test.cpp index 619fa2e..111a660 100644 --- a/test/context_activator_test.cpp +++ b/test/context_activator_test.cpp @@ -19,7 +19,7 @@ struct info template leaf::result f( Ctx & ctx ) { - leaf::context_activator active_context(ctx, leaf::on_deactivation::do_not_propagate); + auto active_context = activate_context(ctx, leaf::on_deactivation::do_not_propagate); return leaf::new_error( info<1>{1} ); } @@ -43,7 +43,7 @@ int main() [&] { auto ctx = leaf::make_context(&handle_error); - leaf::context_activator active_context(ctx, leaf::on_deactivation::propagate); + auto active_context = activate_context(ctx, leaf::on_deactivation::propagate); return f(ctx); }, [&]( leaf::error_info const & error ) diff --git a/test/continuation_test.cpp b/test/continuation_test.cpp index 3847d76..209465f 100644 --- a/test/continuation_test.cpp +++ b/test/continuation_test.cpp @@ -70,7 +70,7 @@ struct io_task_context asio::post( io_ctx, [=]() mutable { - leaf::context_activator active_context(*err_ctx, leaf::on_deactivation::do_not_propagate); + auto active_context = activate_context(*err_ctx, leaf::on_deactivation::do_not_propagate); f(); } ); } diff --git a/test/ctx_remote_handle_all_test.cpp b/test/ctx_remote_handle_all_test.cpp index 369a901..e253f28 100644 --- a/test/ctx_remote_handle_all_test.cpp +++ b/test/ctx_remote_handle_all_test.cpp @@ -20,7 +20,7 @@ struct info template leaf::result f( Ctx & ctx ) { - leaf::context_activator active_context(ctx, leaf::on_deactivation::do_not_propagate); + auto active_context = activate_context(ctx, leaf::on_deactivation::do_not_propagate); return leaf::new_error( info<1>{1} ); } diff --git a/test/ctx_remote_handle_exception_test.cpp b/test/ctx_remote_handle_exception_test.cpp index bce8afd..c1ff02c 100644 --- a/test/ctx_remote_handle_exception_test.cpp +++ b/test/ctx_remote_handle_exception_test.cpp @@ -31,7 +31,7 @@ struct info template void f( Ctx & ctx ) { - leaf::context_activator active_context(ctx, leaf::on_deactivation::do_not_propagate); + auto active_context = activate_context(ctx, leaf::on_deactivation::do_not_propagate); throw leaf::exception(std::exception(), info<1>{1}); } diff --git a/test/ctx_remote_handle_some_test.cpp b/test/ctx_remote_handle_some_test.cpp index 113bd13..8cc4c76 100644 --- a/test/ctx_remote_handle_some_test.cpp +++ b/test/ctx_remote_handle_some_test.cpp @@ -19,7 +19,7 @@ struct info template leaf::result f( Ctx & ctx ) { - leaf::context_activator active_context(ctx, leaf::on_deactivation::do_not_propagate); + auto active_context = activate_context(ctx, leaf::on_deactivation::do_not_propagate); return leaf::new_error( info<1>{1} ); } diff --git a/test/result_state_test.cpp b/test/result_state_test.cpp index 637e5a8..f74f6c8 100644 --- a/test/result_state_test.cpp +++ b/test/result_state_test.cpp @@ -408,7 +408,7 @@ int main() { // error move -> copy context_type ctx; - leaf::context_activator active_context(ctx, leaf::on_deactivation::do_not_propagate); + auto active_context = activate_context(ctx, leaf::on_deactivation::do_not_propagate); leaf::result r1 = leaf::new_error( e_err { } ); BOOST_TEST(!r1); BOOST_TEST_EQ(err::count, 1); @@ -421,7 +421,7 @@ int main() BOOST_TEST_EQ(val::count, 0); { // error copy -> copy context_type ctx; - leaf::context_activator active_context(ctx, leaf::on_deactivation::do_not_propagate); + auto active_context = activate_context(ctx, leaf::on_deactivation::do_not_propagate); leaf::error_id err = leaf::new_error( e_err{ } ); leaf::result r1 = err; BOOST_TEST(!r1); @@ -436,7 +436,7 @@ int main() { // error move -> move context_type ctx; - leaf::context_activator active_context(ctx, leaf::on_deactivation::do_not_propagate); + auto active_context = activate_context(ctx, leaf::on_deactivation::do_not_propagate); leaf::result r1 = leaf::new_error( e_err { } ); BOOST_TEST(!r1); BOOST_TEST_EQ(err::count, 1); @@ -449,7 +449,7 @@ int main() BOOST_TEST_EQ(val::count, 0); { // error copy -> move context_type ctx; - leaf::context_activator active_context(ctx, leaf::on_deactivation::propagate); + auto active_context = activate_context(ctx, leaf::on_deactivation::propagate); leaf::error_id err = leaf::new_error( e_err{ } ); leaf::result r1 = err; BOOST_TEST(!r1); @@ -464,7 +464,7 @@ int main() { // error move -> assign copy context_type ctx; - leaf::context_activator active_context(ctx, leaf::on_deactivation::propagate); + auto active_context = activate_context(ctx, leaf::on_deactivation::propagate); leaf::result r1 = leaf::new_error( e_err { } ); BOOST_TEST(!r1); BOOST_TEST_EQ(err::count, 1); @@ -477,7 +477,7 @@ int main() BOOST_TEST_EQ(val::count, 0); { // error copy -> assign copy context_type ctx; - leaf::context_activator active_context(ctx, leaf::on_deactivation::propagate); + auto active_context = activate_context(ctx, leaf::on_deactivation::propagate); leaf::error_id err = leaf::new_error( e_err{ } ); leaf::result r1 = err; BOOST_TEST(!r1); @@ -492,7 +492,7 @@ int main() { // error move -> assign move context_type ctx; - leaf::context_activator active_context(ctx, leaf::on_deactivation::propagate); + auto active_context = activate_context(ctx, leaf::on_deactivation::propagate); leaf::result r1 = leaf::new_error( e_err { } ); BOOST_TEST(!r1); BOOST_TEST_EQ(err::count, 1); @@ -510,7 +510,7 @@ int main() BOOST_TEST_EQ(val::count, 0); { // error copy -> assign move context_type ctx; - leaf::context_activator active_context(ctx, leaf::on_deactivation::propagate); + auto active_context = activate_context(ctx, leaf::on_deactivation::propagate); leaf::error_id err = leaf::new_error( e_err{ } ); leaf::result r1 = err; BOOST_TEST(!r1); @@ -682,7 +682,7 @@ int main() { // void error move -> copy context_type ctx; - leaf::context_activator active_context(ctx, leaf::on_deactivation::do_not_propagate); + auto active_context = activate_context(ctx, leaf::on_deactivation::do_not_propagate); leaf::result r1 = leaf::new_error( e_err { } ); BOOST_TEST(!r1); BOOST_TEST_EQ(err::count, 1); @@ -693,7 +693,7 @@ int main() BOOST_TEST_EQ(err::count, 0); { // void error copy -> copy context_type ctx; - leaf::context_activator active_context(ctx, leaf::on_deactivation::do_not_propagate); + auto active_context = activate_context(ctx, leaf::on_deactivation::do_not_propagate); leaf::error_id err = leaf::new_error( e_err{ } ); leaf::result r1 = err; BOOST_TEST(!r1); @@ -706,7 +706,7 @@ int main() { // void error move -> move context_type ctx; - leaf::context_activator active_context(ctx, leaf::on_deactivation::do_not_propagate); + auto active_context = activate_context(ctx, leaf::on_deactivation::do_not_propagate); leaf::result r1 = leaf::new_error( e_err { } ); BOOST_TEST(!r1); BOOST_TEST_EQ(err::count, 1); @@ -717,7 +717,7 @@ int main() BOOST_TEST_EQ(err::count, 0); { // void error copy -> move context_type ctx; - leaf::context_activator active_context(ctx, leaf::on_deactivation::propagate); + auto active_context = activate_context(ctx, leaf::on_deactivation::propagate); leaf::error_id err = leaf::new_error( e_err{ } ); leaf::result r1 = err; BOOST_TEST(!r1); @@ -730,7 +730,7 @@ int main() { // void error move -> assign copy context_type ctx; - leaf::context_activator active_context(ctx, leaf::on_deactivation::propagate); + auto active_context = activate_context(ctx, leaf::on_deactivation::propagate); leaf::result r1 = leaf::new_error( e_err { } ); BOOST_TEST(!r1); BOOST_TEST_EQ(err::count, 1); @@ -741,7 +741,7 @@ int main() BOOST_TEST_EQ(err::count, 0); { // void error copy -> assign copy context_type ctx; - leaf::context_activator active_context(ctx, leaf::on_deactivation::propagate); + auto active_context = activate_context(ctx, leaf::on_deactivation::propagate); leaf::error_id err = leaf::new_error( e_err{ } ); leaf::result r1 = err; BOOST_TEST(!r1); @@ -754,7 +754,7 @@ int main() { // void error move -> assign move context_type ctx; - leaf::context_activator active_context(ctx, leaf::on_deactivation::propagate); + auto active_context = activate_context(ctx, leaf::on_deactivation::propagate); leaf::result r1 = leaf::new_error( e_err { } ); BOOST_TEST(!r1); BOOST_TEST_EQ(err::count, 1); @@ -766,7 +766,7 @@ int main() BOOST_TEST_EQ(err::count, 0); { // void error copy -> assign move context_type ctx; - leaf::context_activator active_context(ctx, leaf::on_deactivation::propagate); + auto active_context = activate_context(ctx, leaf::on_deactivation::propagate); leaf::error_id err = leaf::new_error( e_err{ } ); leaf::result r1 = err; BOOST_TEST(!r1);