From 799a48c390441cb1c75838af18167e2a34840d7f Mon Sep 17 00:00:00 2001 From: Klemens Morgenstern Date: Wed, 21 Jun 2023 14:41:50 +0800 Subject: [PATCH] removed code_as_error. --- include/boost/process/v2/exit_code.hpp | 154 +++--------------------- include/boost/process/v2/impl/error.ipp | 2 +- include/boost/process/v2/process.hpp | 7 +- test/v2/pid.cpp | 8 +- test/v2/process.cpp | 29 ++++- 5 files changed, 51 insertions(+), 149 deletions(-) diff --git a/include/boost/process/v2/exit_code.hpp b/include/boost/process/v2/exit_code.hpp index 3835d9f94..3ee580063 100644 --- a/include/boost/process/v2/exit_code.hpp +++ b/include/boost/process/v2/exit_code.hpp @@ -94,12 +94,19 @@ inline int evaluate_exit_code(int code) #endif - -/** Convert the exit-code in a completion into an error if the actual error isn't set. +/// @{ +/** Helper to subsume an exit-code into an error_code if there's no actual error isn't set. * @code {.cpp} * process proc{ctx, "exit", {"1"}}; * - * proc.async_wait(code_as_error( + * proc.async_wait( + * asio::deferred( + * [&proc](error_code ec, int) + * { + * return asio::deferred.values( + * check_exit_code(ec, proc.native_exit_code()) + * ); + * * [](error_code ec) * { * assert(ec.value() == 10); @@ -107,144 +114,19 @@ inline int evaluate_exit_code(int code) * })); * * @endcode - */ -template -struct code_as_error_t -{ - CompletionToken token_; - const error_category & category; - - template - code_as_error_t(Token_ && token, const error_category & category) - : token_(std::forward(token)), category(category) - { - } -}; - -/// Deduction function for code_as_error_t. -template -code_as_error_t code_as_error( - CompletionToken && token, - const error_category & category = error::get_exit_code_category()) -{ - return code_as_error_t::type>( - std::forward(token), category); -}; - -namespace detail -{ + */ -template -struct code_as_error_handler +inline error_code check_exit_code( + error_code &ec, native_exit_code_type native_code, + const error_category & category = error::get_exit_code_category()) { - typedef void result_type; - - template - code_as_error_handler(H && h, const error_category & category) - : handler_(std::forward(h)), category(category) - { - } - - void operator()(error_code ec, native_exit_code_type code) - { - if (!ec) - BOOST_PROCESS_V2_ASSIGN_EC(ec, code, category) - std::move(handler_)(ec); - } - - - Handler handler_; - const error_category & category; -}; - + if (!ec) + BOOST_PROCESS_V2_ASSIGN_EC(ec, native_code, category); + return ec; } +/// @} BOOST_PROCESS_V2_END_NAMESPACE - -#if !defined(BOOST_PROCESS_V2_STANDALONE) -namespace boost -{ -#endif -namespace asio -{ - -template -struct async_result< - BOOST_PROCESS_V2_NAMESPACE::code_as_error_t, - void(BOOST_PROCESS_V2_NAMESPACE::error_code, - BOOST_PROCESS_V2_NAMESPACE::native_exit_code_type)> -{ - using signature = void(BOOST_PROCESS_V2_NAMESPACE::error_code); - using return_type = typename async_result::return_type; - - - template - struct init_wrapper - { - init_wrapper(Initiation init) - : initiation_(std::move(init)) - { - } - - template - void operator()( - Handler && handler, - const BOOST_PROCESS_V2_NAMESPACE::error_category & cat, - Args && ... args) - { - std::move(initiation_)( - BOOST_PROCESS_V2_NAMESPACE::detail::code_as_error_handler::type>( - std::forward(handler), cat), - std::forward(args)...); - } - - Initiation initiation_; - - }; - - template - static BOOST_PROCESS_V2_INITFN_DEDUCED_RESULT_TYPE(CompletionToken, signature, - (async_initiate( - declval::type> >(), - declval(), - declval()...))) - initiate( - Initiation && initiation, - RawCompletionToken && token, - Args &&... args) - { - return async_initiate( - init_wrapper::type>( - std::forward(initiation)), - token.token_, - token.category, - std::forward(args)...); - } -}; - - - - -template