123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944 |
- //
- // async_result.hpp
- // ~~~~~~~~~~~~~~~~
- //
- // Copyright (c) 2003-2024 Christopher M. Kohlhoff (chris at kohlhoff dot com)
- //
- // 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)
- //
- #ifndef BOOST_ASIO_ASYNC_RESULT_HPP
- #define BOOST_ASIO_ASYNC_RESULT_HPP
- #if defined(_MSC_VER) && (_MSC_VER >= 1200)
- # pragma once
- #endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
- #include <boost/asio/detail/config.hpp>
- #include <boost/asio/detail/type_traits.hpp>
- #include <boost/asio/detail/push_options.hpp>
- namespace boost {
- namespace asio {
- #if defined(BOOST_ASIO_HAS_CONCEPTS)
- namespace detail {
- template <typename T>
- struct is_completion_signature : false_type
- {
- };
- template <typename R, typename... Args>
- struct is_completion_signature<R(Args...)> : true_type
- {
- };
- template <typename R, typename... Args>
- struct is_completion_signature<R(Args...) &> : true_type
- {
- };
- template <typename R, typename... Args>
- struct is_completion_signature<R(Args...) &&> : true_type
- {
- };
- # if defined(BOOST_ASIO_HAS_NOEXCEPT_FUNCTION_TYPE)
- template <typename R, typename... Args>
- struct is_completion_signature<R(Args...) noexcept> : true_type
- {
- };
- template <typename R, typename... Args>
- struct is_completion_signature<R(Args...) & noexcept> : true_type
- {
- };
- template <typename R, typename... Args>
- struct is_completion_signature<R(Args...) && noexcept> : true_type
- {
- };
- # endif // defined(BOOST_ASIO_HAS_NOEXCEPT_FUNCTION_TYPE)
- template <typename... T>
- struct are_completion_signatures : false_type
- {
- };
- template <typename T0>
- struct are_completion_signatures<T0>
- : is_completion_signature<T0>
- {
- };
- template <typename T0, typename... TN>
- struct are_completion_signatures<T0, TN...>
- : integral_constant<bool, (
- is_completion_signature<T0>::value
- && are_completion_signatures<TN...>::value)>
- {
- };
- template <typename T, typename... Args>
- BOOST_ASIO_CONCEPT callable_with = requires(T&& t, Args&&... args)
- {
- static_cast<T&&>(t)(static_cast<Args&&>(args)...);
- };
- template <typename T, typename... Signatures>
- struct is_completion_handler_for : false_type
- {
- };
- template <typename T, typename R, typename... Args>
- struct is_completion_handler_for<T, R(Args...)>
- : integral_constant<bool, (callable_with<decay_t<T>, Args...>)>
- {
- };
- template <typename T, typename R, typename... Args>
- struct is_completion_handler_for<T, R(Args...) &>
- : integral_constant<bool, (callable_with<decay_t<T>&, Args...>)>
- {
- };
- template <typename T, typename R, typename... Args>
- struct is_completion_handler_for<T, R(Args...) &&>
- : integral_constant<bool, (callable_with<decay_t<T>&&, Args...>)>
- {
- };
- # if defined(BOOST_ASIO_HAS_NOEXCEPT_FUNCTION_TYPE)
- template <typename T, typename R, typename... Args>
- struct is_completion_handler_for<T, R(Args...) noexcept>
- : integral_constant<bool, (callable_with<decay_t<T>, Args...>)>
- {
- };
- template <typename T, typename R, typename... Args>
- struct is_completion_handler_for<T, R(Args...) & noexcept>
- : integral_constant<bool, (callable_with<decay_t<T>&, Args...>)>
- {
- };
- template <typename T, typename R, typename... Args>
- struct is_completion_handler_for<T, R(Args...) && noexcept>
- : integral_constant<bool, (callable_with<decay_t<T>&&, Args...>)>
- {
- };
- # endif // defined(BOOST_ASIO_HAS_NOEXCEPT_FUNCTION_TYPE)
- template <typename T, typename Signature0, typename... SignatureN>
- struct is_completion_handler_for<T, Signature0, SignatureN...>
- : integral_constant<bool, (
- is_completion_handler_for<T, Signature0>::value
- && is_completion_handler_for<T, SignatureN...>::value)>
- {
- };
- } // namespace detail
- template <typename T>
- BOOST_ASIO_CONCEPT completion_signature =
- detail::is_completion_signature<T>::value;
- #define BOOST_ASIO_COMPLETION_SIGNATURE \
- ::boost::asio::completion_signature
- template <typename T, typename... Signatures>
- BOOST_ASIO_CONCEPT completion_handler_for =
- detail::are_completion_signatures<Signatures...>::value
- && detail::is_completion_handler_for<T, Signatures...>::value;
- #define BOOST_ASIO_COMPLETION_HANDLER_FOR(sig) \
- ::boost::asio::completion_handler_for<sig>
- #define BOOST_ASIO_COMPLETION_HANDLER_FOR2(sig0, sig1) \
- ::boost::asio::completion_handler_for<sig0, sig1>
- #define BOOST_ASIO_COMPLETION_HANDLER_FOR3(sig0, sig1, sig2) \
- ::boost::asio::completion_handler_for<sig0, sig1, sig2>
- #else // defined(BOOST_ASIO_HAS_CONCEPTS)
- #define BOOST_ASIO_COMPLETION_SIGNATURE typename
- #define BOOST_ASIO_COMPLETION_HANDLER_FOR(sig) typename
- #define BOOST_ASIO_COMPLETION_HANDLER_FOR2(sig0, sig1) typename
- #define BOOST_ASIO_COMPLETION_HANDLER_FOR3(sig0, sig1, sig2) typename
- #endif // defined(BOOST_ASIO_HAS_CONCEPTS)
- namespace detail {
- template <typename T>
- struct is_lvalue_completion_signature : false_type
- {
- };
- template <typename R, typename... Args>
- struct is_lvalue_completion_signature<R(Args...) &> : true_type
- {
- };
- # if defined(BOOST_ASIO_HAS_NOEXCEPT_FUNCTION_TYPE)
- template <typename R, typename... Args>
- struct is_lvalue_completion_signature<R(Args...) & noexcept> : true_type
- {
- };
- # endif // defined(BOOST_ASIO_HAS_NOEXCEPT_FUNCTION_TYPE)
- template <typename... Signatures>
- struct are_any_lvalue_completion_signatures : false_type
- {
- };
- template <typename Sig0>
- struct are_any_lvalue_completion_signatures<Sig0>
- : is_lvalue_completion_signature<Sig0>
- {
- };
- template <typename Sig0, typename... SigN>
- struct are_any_lvalue_completion_signatures<Sig0, SigN...>
- : integral_constant<bool, (
- is_lvalue_completion_signature<Sig0>::value
- || are_any_lvalue_completion_signatures<SigN...>::value)>
- {
- };
- template <typename T>
- struct is_rvalue_completion_signature : false_type
- {
- };
- template <typename R, typename... Args>
- struct is_rvalue_completion_signature<R(Args...) &&> : true_type
- {
- };
- # if defined(BOOST_ASIO_HAS_NOEXCEPT_FUNCTION_TYPE)
- template <typename R, typename... Args>
- struct is_rvalue_completion_signature<R(Args...) && noexcept> : true_type
- {
- };
- # endif // defined(BOOST_ASIO_HAS_NOEXCEPT_FUNCTION_TYPE)
- template <typename... Signatures>
- struct are_any_rvalue_completion_signatures : false_type
- {
- };
- template <typename Sig0>
- struct are_any_rvalue_completion_signatures<Sig0>
- : is_rvalue_completion_signature<Sig0>
- {
- };
- template <typename Sig0, typename... SigN>
- struct are_any_rvalue_completion_signatures<Sig0, SigN...>
- : integral_constant<bool, (
- is_rvalue_completion_signature<Sig0>::value
- || are_any_rvalue_completion_signatures<SigN...>::value)>
- {
- };
- template <typename T>
- struct simple_completion_signature;
- template <typename R, typename... Args>
- struct simple_completion_signature<R(Args...)>
- {
- typedef R type(Args...);
- };
- template <typename R, typename... Args>
- struct simple_completion_signature<R(Args...) &>
- {
- typedef R type(Args...);
- };
- template <typename R, typename... Args>
- struct simple_completion_signature<R(Args...) &&>
- {
- typedef R type(Args...);
- };
- # if defined(BOOST_ASIO_HAS_NOEXCEPT_FUNCTION_TYPE)
- template <typename R, typename... Args>
- struct simple_completion_signature<R(Args...) noexcept>
- {
- typedef R type(Args...);
- };
- template <typename R, typename... Args>
- struct simple_completion_signature<R(Args...) & noexcept>
- {
- typedef R type(Args...);
- };
- template <typename R, typename... Args>
- struct simple_completion_signature<R(Args...) && noexcept>
- {
- typedef R type(Args...);
- };
- # endif // defined(BOOST_ASIO_HAS_NOEXCEPT_FUNCTION_TYPE)
- template <typename CompletionToken,
- BOOST_ASIO_COMPLETION_SIGNATURE... Signatures>
- class completion_handler_async_result
- {
- public:
- typedef CompletionToken completion_handler_type;
- typedef void return_type;
- explicit completion_handler_async_result(completion_handler_type&)
- {
- }
- return_type get()
- {
- }
- template <typename Initiation,
- BOOST_ASIO_COMPLETION_HANDLER_FOR(Signatures...) RawCompletionToken,
- typename... Args>
- static return_type initiate(Initiation&& initiation,
- RawCompletionToken&& token, Args&&... args)
- {
- static_cast<Initiation&&>(initiation)(
- static_cast<RawCompletionToken&&>(token),
- static_cast<Args&&>(args)...);
- }
- private:
- completion_handler_async_result(
- const completion_handler_async_result&) = delete;
- completion_handler_async_result& operator=(
- const completion_handler_async_result&) = delete;
- };
- } // namespace detail
- #if defined(GENERATING_DOCUMENTATION)
- /// An interface for customising the behaviour of an initiating function.
- /**
- * The async_result traits class is used for determining:
- *
- * @li the concrete completion handler type to be called at the end of the
- * asynchronous operation;
- *
- * @li the initiating function return type; and
- *
- * @li how the return value of the initiating function is obtained.
- *
- * The trait allows the handler and return types to be determined at the point
- * where the specific completion handler signature is known.
- *
- * This template may be specialised for user-defined completion token types.
- * The primary template assumes that the CompletionToken is the completion
- * handler.
- */
- template <typename CompletionToken,
- BOOST_ASIO_COMPLETION_SIGNATURE... Signatures>
- class async_result
- {
- public:
- /// The concrete completion handler type for the specific signature.
- typedef CompletionToken completion_handler_type;
- /// The return type of the initiating function.
- typedef void return_type;
- /// Construct an async result from a given handler.
- /**
- * When using a specalised async_result, the constructor has an opportunity
- * to initialise some state associated with the completion handler, which is
- * then returned from the initiating function.
- */
- explicit async_result(completion_handler_type& h);
- /// Obtain the value to be returned from the initiating function.
- return_type get();
- /// Initiate the asynchronous operation that will produce the result, and
- /// obtain the value to be returned from the initiating function.
- template <typename Initiation, typename RawCompletionToken, typename... Args>
- static return_type initiate(
- Initiation&& initiation,
- RawCompletionToken&& token,
- Args&&... args);
- private:
- async_result(const async_result&) = delete;
- async_result& operator=(const async_result&) = delete;
- };
- #else // defined(GENERATING_DOCUMENTATION)
- template <typename CompletionToken,
- BOOST_ASIO_COMPLETION_SIGNATURE... Signatures>
- class async_result :
- public conditional_t<
- detail::are_any_lvalue_completion_signatures<Signatures...>::value
- || !detail::are_any_rvalue_completion_signatures<Signatures...>::value,
- detail::completion_handler_async_result<CompletionToken, Signatures...>,
- async_result<CompletionToken,
- typename detail::simple_completion_signature<Signatures>::type...>
- >
- {
- public:
- typedef conditional_t<
- detail::are_any_lvalue_completion_signatures<Signatures...>::value
- || !detail::are_any_rvalue_completion_signatures<Signatures...>::value,
- detail::completion_handler_async_result<CompletionToken, Signatures...>,
- async_result<CompletionToken,
- typename detail::simple_completion_signature<Signatures>::type...>
- > base_type;
- using base_type::base_type;
- private:
- async_result(const async_result&) = delete;
- async_result& operator=(const async_result&) = delete;
- };
- template <BOOST_ASIO_COMPLETION_SIGNATURE... Signatures>
- class async_result<void, Signatures...>
- {
- // Empty.
- };
- #endif // defined(GENERATING_DOCUMENTATION)
- /// Helper template to deduce the handler type from a CompletionToken, capture
- /// a local copy of the handler, and then create an async_result for the
- /// handler.
- template <typename CompletionToken,
- BOOST_ASIO_COMPLETION_SIGNATURE... Signatures>
- struct async_completion
- {
- /// The real handler type to be used for the asynchronous operation.
- typedef typename boost::asio::async_result<
- decay_t<CompletionToken>, Signatures...>::completion_handler_type
- completion_handler_type;
- /// Constructor.
- /**
- * The constructor creates the concrete completion handler and makes the link
- * between the handler and the asynchronous result.
- */
- explicit async_completion(CompletionToken& token)
- : completion_handler(static_cast<conditional_t<
- is_same<CompletionToken, completion_handler_type>::value,
- completion_handler_type&, CompletionToken&&>>(token)),
- result(completion_handler)
- {
- }
- /// A copy of, or reference to, a real handler object.
- conditional_t<
- is_same<CompletionToken, completion_handler_type>::value,
- completion_handler_type&, completion_handler_type> completion_handler;
- /// The result of the asynchronous operation's initiating function.
- async_result<decay_t<CompletionToken>, Signatures...> result;
- };
- namespace detail {
- struct async_result_memfns_base
- {
- void initiate();
- };
- template <typename T>
- struct async_result_memfns_derived
- : T, async_result_memfns_base
- {
- };
- template <typename T, T>
- struct async_result_memfns_check
- {
- };
- template <typename>
- char (&async_result_initiate_memfn_helper(...))[2];
- template <typename T>
- char async_result_initiate_memfn_helper(
- async_result_memfns_check<
- void (async_result_memfns_base::*)(),
- &async_result_memfns_derived<T>::initiate>*);
- template <typename CompletionToken,
- BOOST_ASIO_COMPLETION_SIGNATURE... Signatures>
- struct async_result_has_initiate_memfn
- : integral_constant<bool, sizeof(async_result_initiate_memfn_helper<
- async_result<decay_t<CompletionToken>, Signatures...>
- >(0)) != 1>
- {
- };
- } // namespace detail
- #if defined(GENERATING_DOCUMENTATION)
- # define BOOST_ASIO_INITFN_RESULT_TYPE(ct, sig) \
- void_or_deduced
- # define BOOST_ASIO_INITFN_RESULT_TYPE2(ct, sig0, sig1) \
- void_or_deduced
- # define BOOST_ASIO_INITFN_RESULT_TYPE3(ct, sig0, sig1, sig2) \
- void_or_deduced
- #else
- # define BOOST_ASIO_INITFN_RESULT_TYPE(ct, sig) \
- typename ::boost::asio::async_result< \
- typename ::boost::asio::decay<ct>::type, sig>::return_type
- # define BOOST_ASIO_INITFN_RESULT_TYPE2(ct, sig0, sig1) \
- typename ::boost::asio::async_result< \
- typename ::boost::asio::decay<ct>::type, sig0, sig1>::return_type
- # define BOOST_ASIO_INITFN_RESULT_TYPE3(ct, sig0, sig1, sig2) \
- typename ::boost::asio::async_result< \
- typename ::boost::asio::decay<ct>::type, sig0, sig1, sig2>::return_type
- #define BOOST_ASIO_HANDLER_TYPE(ct, sig) \
- typename ::boost::asio::async_result< \
- typename ::boost::asio::decay<ct>::type, sig>::completion_handler_type
- #define BOOST_ASIO_HANDLER_TYPE2(ct, sig0, sig1) \
- typename ::boost::asio::async_result< \
- typename ::boost::asio::decay<ct>::type, \
- sig0, sig1>::completion_handler_type
- #define BOOST_ASIO_HANDLER_TYPE3(ct, sig0, sig1, sig2) \
- typename ::boost::asio::async_result< \
- typename ::boost::asio::decay<ct>::type, \
- sig0, sig1, sig2>::completion_handler_type
- #endif
- #if defined(GENERATING_DOCUMENTATION)
- # define BOOST_ASIO_INITFN_AUTO_RESULT_TYPE(ct, sig) \
- auto
- # define BOOST_ASIO_INITFN_AUTO_RESULT_TYPE2(ct, sig0, sig1) \
- auto
- # define BOOST_ASIO_INITFN_AUTO_RESULT_TYPE3(ct, sig0, sig1, sig2) \
- auto
- #elif defined(BOOST_ASIO_HAS_RETURN_TYPE_DEDUCTION)
- # define BOOST_ASIO_INITFN_AUTO_RESULT_TYPE(ct, sig) \
- auto
- # define BOOST_ASIO_INITFN_AUTO_RESULT_TYPE2(ct, sig0, sig1) \
- auto
- # define BOOST_ASIO_INITFN_AUTO_RESULT_TYPE3(ct, sig0, sig1, sig2) \
- auto
- #else
- # define BOOST_ASIO_INITFN_AUTO_RESULT_TYPE(ct, sig) \
- BOOST_ASIO_INITFN_RESULT_TYPE(ct, sig)
- # define BOOST_ASIO_INITFN_AUTO_RESULT_TYPE2(ct, sig0, sig1) \
- BOOST_ASIO_INITFN_RESULT_TYPE2(ct, sig0, sig1)
- # define BOOST_ASIO_INITFN_AUTO_RESULT_TYPE3(ct, sig0, sig1, sig2) \
- BOOST_ASIO_INITFN_RESULT_TYPE3(ct, sig0, sig1, sig2)
- #endif
- #if defined(GENERATING_DOCUMENTATION)
- # define BOOST_ASIO_INITFN_AUTO_RESULT_TYPE_PREFIX(ct, sig) \
- auto
- # define BOOST_ASIO_INITFN_AUTO_RESULT_TYPE_PREFIX2(ct, sig0, sig1) \
- auto
- # define BOOST_ASIO_INITFN_AUTO_RESULT_TYPE_PREFIX3(ct, sig0, sig1, sig2) \
- auto
- # define BOOST_ASIO_INITFN_AUTO_RESULT_TYPE_SUFFIX(expr)
- #elif defined(BOOST_ASIO_HAS_RETURN_TYPE_DEDUCTION)
- # define BOOST_ASIO_INITFN_AUTO_RESULT_TYPE_PREFIX(ct, sig) \
- auto
- # define BOOST_ASIO_INITFN_AUTO_RESULT_TYPE_PREFIX2(ct, sig0, sig1) \
- auto
- # define BOOST_ASIO_INITFN_AUTO_RESULT_TYPE_PREFIX3(ct, sig0, sig1, sig2) \
- auto
- # define BOOST_ASIO_INITFN_AUTO_RESULT_TYPE_SUFFIX(expr)
- #else
- # define BOOST_ASIO_INITFN_AUTO_RESULT_TYPE_PREFIX(ct, sig) \
- auto
- # define BOOST_ASIO_INITFN_AUTO_RESULT_TYPE_PREFIX2(ct, sig0, sig1) \
- auto
- # define BOOST_ASIO_INITFN_AUTO_RESULT_TYPE_PREFIX3(ct, sig0, sig1, sig2) \
- auto
- # define BOOST_ASIO_INITFN_AUTO_RESULT_TYPE_SUFFIX(expr) -> decltype expr
- #endif
- #if defined(GENERATING_DOCUMENTATION)
- # define BOOST_ASIO_INITFN_DEDUCED_RESULT_TYPE(ct, sig, expr) \
- void_or_deduced
- # define BOOST_ASIO_INITFN_DEDUCED_RESULT_TYPE2(ct, sig0, sig1, expr) \
- void_or_deduced
- # define BOOST_ASIO_INITFN_DEDUCED_RESULT_TYPE3(ct, sig0, sig1, sig2, expr) \
- void_or_deduced
- #else
- # define BOOST_ASIO_INITFN_DEDUCED_RESULT_TYPE(ct, sig, expr) \
- decltype expr
- # define BOOST_ASIO_INITFN_DEDUCED_RESULT_TYPE2(ct, sig0, sig1, expr) \
- decltype expr
- # define BOOST_ASIO_INITFN_DEDUCED_RESULT_TYPE3(ct, sig0, sig1, sig2, expr) \
- decltype expr
- #endif
- #if defined(GENERATING_DOCUMENTATION)
- template <typename CompletionToken,
- completion_signature... Signatures,
- typename Initiation, typename... Args>
- void_or_deduced async_initiate(
- Initiation&& initiation,
- type_identity_t<CompletionToken>& token,
- Args&&... args);
- #else // defined(GENERATING_DOCUMENTATION)
- template <typename CompletionToken,
- BOOST_ASIO_COMPLETION_SIGNATURE... Signatures,
- typename Initiation, typename... Args>
- inline auto async_initiate(Initiation&& initiation,
- type_identity_t<CompletionToken>& token, Args&&... args)
- -> constraint_t<
- detail::async_result_has_initiate_memfn<
- CompletionToken, Signatures...>::value,
- decltype(
- async_result<decay_t<CompletionToken>, Signatures...>::initiate(
- static_cast<Initiation&&>(initiation),
- static_cast<CompletionToken&&>(token),
- static_cast<Args&&>(args)...))>
- {
- return async_result<decay_t<CompletionToken>, Signatures...>::initiate(
- static_cast<Initiation&&>(initiation),
- static_cast<CompletionToken&&>(token),
- static_cast<Args&&>(args)...);
- }
- template <typename CompletionToken,
- BOOST_ASIO_COMPLETION_SIGNATURE... Signatures,
- typename Initiation, typename... Args>
- inline constraint_t<
- !detail::async_result_has_initiate_memfn<
- CompletionToken, Signatures...>::value,
- typename async_result<decay_t<CompletionToken>, Signatures...>::return_type>
- async_initiate(Initiation&& initiation,
- type_identity_t<CompletionToken>& token, Args&&... args)
- {
- async_completion<CompletionToken, Signatures...> completion(token);
- static_cast<Initiation&&>(initiation)(
- static_cast<
- typename async_result<decay_t<CompletionToken>,
- Signatures...>::completion_handler_type&&>(
- completion.completion_handler),
- static_cast<Args&&>(args)...);
- return completion.result.get();
- }
- #endif // defined(GENERATING_DOCUMENTATION)
- #if defined(BOOST_ASIO_HAS_CONCEPTS)
- namespace detail {
- template <typename... Signatures>
- struct initiation_archetype
- {
- template <completion_handler_for<Signatures...> CompletionHandler>
- void operator()(CompletionHandler&&) const
- {
- }
- };
- } // namespace detail
- template <typename T, typename... Signatures>
- BOOST_ASIO_CONCEPT completion_token_for =
- detail::are_completion_signatures<Signatures...>::value
- &&
- requires(T&& t)
- {
- async_initiate<T, Signatures...>(
- detail::initiation_archetype<Signatures...>{}, t);
- };
- #define BOOST_ASIO_COMPLETION_TOKEN_FOR(sig) \
- ::boost::asio::completion_token_for<sig>
- #define BOOST_ASIO_COMPLETION_TOKEN_FOR2(sig0, sig1) \
- ::boost::asio::completion_token_for<sig0, sig1>
- #define BOOST_ASIO_COMPLETION_TOKEN_FOR3(sig0, sig1, sig2) \
- ::boost::asio::completion_token_for<sig0, sig1, sig2>
- #else // defined(BOOST_ASIO_HAS_CONCEPTS)
- #define BOOST_ASIO_COMPLETION_TOKEN_FOR(sig) typename
- #define BOOST_ASIO_COMPLETION_TOKEN_FOR2(sig0, sig1) typename
- #define BOOST_ASIO_COMPLETION_TOKEN_FOR3(sig0, sig1, sig2) typename
- #endif // defined(BOOST_ASIO_HAS_CONCEPTS)
- namespace detail {
- struct async_operation_probe {};
- struct async_operation_probe_result {};
- template <typename Call, typename = void>
- struct is_async_operation_call : false_type
- {
- };
- template <typename Call>
- struct is_async_operation_call<Call,
- void_t<
- enable_if_t<
- is_same<
- result_of_t<Call>,
- async_operation_probe_result
- >::value
- >
- >
- > : true_type
- {
- };
- } // namespace detail
- #if !defined(GENERATING_DOCUMENTATION)
- template <typename... Signatures>
- class async_result<detail::async_operation_probe, Signatures...>
- {
- public:
- typedef detail::async_operation_probe_result return_type;
- template <typename Initiation, typename... InitArgs>
- static return_type initiate(Initiation&&,
- detail::async_operation_probe, InitArgs&&...)
- {
- return return_type();
- }
- };
- #endif // !defined(GENERATING_DOCUMENTATION)
- #if defined(GENERATING_DOCUMENTATION)
- /// The is_async_operation trait detects whether a type @c T and arguments
- /// @c Args... may be used to initiate an asynchronous operation.
- /**
- * Class template @c is_async_operation is a trait is derived from @c true_type
- * if the expression <tt>T(Args..., token)</tt> initiates an asynchronous
- * operation, where @c token is an unspecified completion token type. Otherwise,
- * @c is_async_operation is derived from @c false_type.
- */
- template <typename T, typename... Args>
- struct is_async_operation : integral_constant<bool, automatically_determined>
- {
- };
- #else // defined(GENERATING_DOCUMENTATION)
- template <typename T, typename... Args>
- struct is_async_operation :
- detail::is_async_operation_call<
- T(Args..., detail::async_operation_probe)>
- {
- };
- #endif // defined(GENERATING_DOCUMENTATION)
- #if defined(BOOST_ASIO_HAS_CONCEPTS)
- template <typename T, typename... Args>
- BOOST_ASIO_CONCEPT async_operation = is_async_operation<T, Args...>::value;
- #define BOOST_ASIO_ASYNC_OPERATION(t) \
- ::boost::asio::async_operation<t>
- #define BOOST_ASIO_ASYNC_OPERATION1(t, a0) \
- ::boost::asio::async_operation<t, a0>
- #define BOOST_ASIO_ASYNC_OPERATION2(t, a0, a1) \
- ::boost::asio::async_operation<t, a0, a1>
- #define BOOST_ASIO_ASYNC_OPERATION3(t, a0, a1, a2) \
- ::boost::asio::async_operation<t, a0, a1, a2>
- #else // defined(BOOST_ASIO_HAS_CONCEPTS)
- #define BOOST_ASIO_ASYNC_OPERATION(t) typename
- #define BOOST_ASIO_ASYNC_OPERATION1(t, a0) typename
- #define BOOST_ASIO_ASYNC_OPERATION2(t, a0, a1) typename
- #define BOOST_ASIO_ASYNC_OPERATION3(t, a0, a1, a2) typename
- #endif // defined(BOOST_ASIO_HAS_CONCEPTS)
- namespace detail {
- struct completion_signature_probe {};
- template <typename... T>
- struct completion_signature_probe_result
- {
- template <template <typename...> class Op>
- struct apply
- {
- typedef Op<T...> type;
- };
- };
- template <typename T>
- struct completion_signature_probe_result<T>
- {
- typedef T type;
- template <template <typename...> class Op>
- struct apply
- {
- typedef Op<T> type;
- };
- };
- template <>
- struct completion_signature_probe_result<void>
- {
- template <template <typename...> class Op>
- struct apply
- {
- typedef Op<> type;
- };
- };
- } // namespace detail
- #if !defined(GENERATING_DOCUMENTATION)
- template <typename... Signatures>
- class async_result<detail::completion_signature_probe, Signatures...>
- {
- public:
- typedef detail::completion_signature_probe_result<Signatures...> return_type;
- template <typename Initiation, typename... InitArgs>
- static return_type initiate(Initiation&&,
- detail::completion_signature_probe, InitArgs&&...)
- {
- return return_type();
- }
- };
- template <typename Signature>
- class async_result<detail::completion_signature_probe, Signature>
- {
- public:
- typedef detail::completion_signature_probe_result<Signature> return_type;
- template <typename Initiation, typename... InitArgs>
- static return_type initiate(Initiation&&,
- detail::completion_signature_probe, InitArgs&&...)
- {
- return return_type();
- }
- };
- #endif // !defined(GENERATING_DOCUMENTATION)
- #if defined(GENERATING_DOCUMENTATION)
- /// The completion_signature_of trait determines the completion signature
- /// of an asynchronous operation.
- /**
- * Class template @c completion_signature_of is a trait with a member type
- * alias @c type that denotes the completion signature of the asynchronous
- * operation initiated by the expression <tt>T(Args..., token)</tt> operation,
- * where @c token is an unspecified completion token type. If the asynchronous
- * operation does not have exactly one completion signature, the instantion of
- * the trait is well-formed but the member type alias @c type is omitted. If
- * the expression <tt>T(Args..., token)</tt> is not an asynchronous operation
- * then use of the trait is ill-formed.
- */
- template <typename T, typename... Args>
- struct completion_signature_of
- {
- typedef automatically_determined type;
- };
- #else // defined(GENERATING_DOCUMENTATION)
- template <typename T, typename... Args>
- struct completion_signature_of :
- result_of_t<T(Args..., detail::completion_signature_probe)>
- {
- };
- #endif // defined(GENERATING_DOCUMENTATION)
- template <typename T, typename... Args>
- using completion_signature_of_t =
- typename completion_signature_of<T, Args...>::type;
- namespace detail {
- template <typename T, typename = void>
- struct default_completion_token_impl
- {
- typedef void type;
- };
- template <typename T>
- struct default_completion_token_impl<T,
- void_t<typename T::default_completion_token_type>
- >
- {
- typedef typename T::default_completion_token_type type;
- };
- } // namespace detail
- #if defined(GENERATING_DOCUMENTATION)
- /// Traits type used to determine the default completion token type associated
- /// with a type (such as an executor).
- /**
- * A program may specialise this traits type if the @c T template parameter in
- * the specialisation is a user-defined type.
- *
- * Specialisations of this trait may provide a nested typedef @c type, which is
- * a default-constructible completion token type.
- */
- template <typename T>
- struct default_completion_token
- {
- /// If @c T has a nested type @c default_completion_token_type,
- /// <tt>T::default_completion_token_type</tt>. Otherwise the typedef @c type
- /// is not defined.
- typedef see_below type;
- };
- #else
- template <typename T>
- struct default_completion_token
- : detail::default_completion_token_impl<T>
- {
- };
- #endif
- template <typename T>
- using default_completion_token_t = typename default_completion_token<T>::type;
- #define BOOST_ASIO_DEFAULT_COMPLETION_TOKEN_TYPE(e) \
- = typename ::boost::asio::default_completion_token<e>::type
- #define BOOST_ASIO_DEFAULT_COMPLETION_TOKEN(e) \
- = typename ::boost::asio::default_completion_token<e>::type()
- } // namespace asio
- } // namespace boost
- #include <boost/asio/detail/pop_options.hpp>
- #endif // BOOST_ASIO_ASYNC_RESULT_HPP
|