Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-12-15 09:44:10

0001 //
0002 // async_result.hpp
0003 // ~~~~~~~~~~~~~~~~
0004 //
0005 // Copyright (c) 2003-2025 Christopher M. Kohlhoff (chris at kohlhoff dot com)
0006 //
0007 // Distributed under the Boost Software License, Version 1.0. (See accompanying
0008 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
0009 //
0010 
0011 #ifndef BOOST_ASIO_ASYNC_RESULT_HPP
0012 #define BOOST_ASIO_ASYNC_RESULT_HPP
0013 
0014 #if defined(_MSC_VER) && (_MSC_VER >= 1200)
0015 # pragma once
0016 #endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
0017 
0018 #include <boost/asio/detail/config.hpp>
0019 #include <boost/asio/detail/type_traits.hpp>
0020 
0021 #include <boost/asio/detail/push_options.hpp>
0022 
0023 namespace boost {
0024 namespace asio {
0025 namespace detail {
0026 
0027 template <typename T>
0028 struct is_completion_signature : false_type
0029 {
0030 };
0031 
0032 template <typename R, typename... Args>
0033 struct is_completion_signature<R(Args...)> : true_type
0034 {
0035 };
0036 
0037 template <typename R, typename... Args>
0038 struct is_completion_signature<R(Args...) &> : true_type
0039 {
0040 };
0041 
0042 template <typename R, typename... Args>
0043 struct is_completion_signature<R(Args...) &&> : true_type
0044 {
0045 };
0046 
0047 # if defined(BOOST_ASIO_HAS_NOEXCEPT_FUNCTION_TYPE)
0048 
0049 template <typename R, typename... Args>
0050 struct is_completion_signature<R(Args...) noexcept> : true_type
0051 {
0052 };
0053 
0054 template <typename R, typename... Args>
0055 struct is_completion_signature<R(Args...) & noexcept> : true_type
0056 {
0057 };
0058 
0059 template <typename R, typename... Args>
0060 struct is_completion_signature<R(Args...) && noexcept> : true_type
0061 {
0062 };
0063 
0064 # endif // defined(BOOST_ASIO_HAS_NOEXCEPT_FUNCTION_TYPE)
0065 
0066 template <typename... T>
0067 struct are_completion_signatures : false_type
0068 {
0069 };
0070 
0071 template <>
0072 struct are_completion_signatures<>
0073   : true_type
0074 {
0075 };
0076 
0077 template <typename T0>
0078 struct are_completion_signatures<T0>
0079   : is_completion_signature<T0>
0080 {
0081 };
0082 
0083 template <typename T0, typename... TN>
0084 struct are_completion_signatures<T0, TN...>
0085   : integral_constant<bool, (
0086       is_completion_signature<T0>::value
0087         && are_completion_signatures<TN...>::value)>
0088 {
0089 };
0090 
0091 } // namespace detail
0092 
0093 #if defined(BOOST_ASIO_HAS_CONCEPTS)
0094 
0095 namespace detail {
0096 
0097 template <typename T, typename... Args>
0098 BOOST_ASIO_CONCEPT callable_with = requires(T&& t, Args&&... args)
0099 {
0100   static_cast<T&&>(t)(static_cast<Args&&>(args)...);
0101 };
0102 
0103 template <typename T, typename... Signatures>
0104 struct is_completion_handler_for : false_type
0105 {
0106 };
0107 
0108 template <typename T, typename R, typename... Args>
0109 struct is_completion_handler_for<T, R(Args...)>
0110   : integral_constant<bool, (callable_with<decay_t<T>, Args...>)>
0111 {
0112 };
0113 
0114 template <typename T, typename R, typename... Args>
0115 struct is_completion_handler_for<T, R(Args...) &>
0116   : integral_constant<bool, (callable_with<decay_t<T>&, Args...>)>
0117 {
0118 };
0119 
0120 template <typename T, typename R, typename... Args>
0121 struct is_completion_handler_for<T, R(Args...) &&>
0122   : integral_constant<bool, (callable_with<decay_t<T>&&, Args...>)>
0123 {
0124 };
0125 
0126 # if defined(BOOST_ASIO_HAS_NOEXCEPT_FUNCTION_TYPE)
0127 
0128 template <typename T, typename R, typename... Args>
0129 struct is_completion_handler_for<T, R(Args...) noexcept>
0130   : integral_constant<bool, (callable_with<decay_t<T>, Args...>)>
0131 {
0132 };
0133 
0134 template <typename T, typename R, typename... Args>
0135 struct is_completion_handler_for<T, R(Args...) & noexcept>
0136   : integral_constant<bool, (callable_with<decay_t<T>&, Args...>)>
0137 {
0138 };
0139 
0140 template <typename T, typename R, typename... Args>
0141 struct is_completion_handler_for<T, R(Args...) && noexcept>
0142   : integral_constant<bool, (callable_with<decay_t<T>&&, Args...>)>
0143 {
0144 };
0145 
0146 # endif // defined(BOOST_ASIO_HAS_NOEXCEPT_FUNCTION_TYPE)
0147 
0148 template <typename T, typename Signature0, typename... SignatureN>
0149 struct is_completion_handler_for<T, Signature0, SignatureN...>
0150   : integral_constant<bool, (
0151       is_completion_handler_for<T, Signature0>::value
0152         && is_completion_handler_for<T, SignatureN...>::value)>
0153 {
0154 };
0155 
0156 } // namespace detail
0157 
0158 template <typename T>
0159 BOOST_ASIO_CONCEPT completion_signature =
0160   detail::is_completion_signature<T>::value;
0161 
0162 #define BOOST_ASIO_COMPLETION_SIGNATURE \
0163   ::boost::asio::completion_signature
0164 
0165 template <typename T, typename... Signatures>
0166 BOOST_ASIO_CONCEPT completion_handler_for =
0167   detail::are_completion_signatures<Signatures...>::value
0168     && detail::is_completion_handler_for<T, Signatures...>::value;
0169 
0170 #define BOOST_ASIO_COMPLETION_HANDLER_FOR(sig) \
0171   ::boost::asio::completion_handler_for<sig>
0172 #define BOOST_ASIO_COMPLETION_HANDLER_FOR2(sig0, sig1) \
0173   ::boost::asio::completion_handler_for<sig0, sig1>
0174 #define BOOST_ASIO_COMPLETION_HANDLER_FOR3(sig0, sig1, sig2) \
0175   ::boost::asio::completion_handler_for<sig0, sig1, sig2>
0176 
0177 #else // defined(BOOST_ASIO_HAS_CONCEPTS)
0178 
0179 #define BOOST_ASIO_COMPLETION_SIGNATURE typename
0180 #define BOOST_ASIO_COMPLETION_HANDLER_FOR(sig) typename
0181 #define BOOST_ASIO_COMPLETION_HANDLER_FOR2(sig0, sig1) typename
0182 #define BOOST_ASIO_COMPLETION_HANDLER_FOR3(sig0, sig1, sig2) typename
0183 
0184 #endif // defined(BOOST_ASIO_HAS_CONCEPTS)
0185 
0186 namespace detail {
0187 
0188 template <typename T>
0189 struct is_lvalue_completion_signature : false_type
0190 {
0191 };
0192 
0193 template <typename R, typename... Args>
0194 struct is_lvalue_completion_signature<R(Args...) &> : true_type
0195 {
0196 };
0197 
0198 # if defined(BOOST_ASIO_HAS_NOEXCEPT_FUNCTION_TYPE)
0199 
0200 template <typename R, typename... Args>
0201 struct is_lvalue_completion_signature<R(Args...) & noexcept> : true_type
0202 {
0203 };
0204 
0205 # endif // defined(BOOST_ASIO_HAS_NOEXCEPT_FUNCTION_TYPE)
0206 
0207 template <typename... Signatures>
0208 struct are_any_lvalue_completion_signatures : false_type
0209 {
0210 };
0211 
0212 template <typename Sig0>
0213 struct are_any_lvalue_completion_signatures<Sig0>
0214   : is_lvalue_completion_signature<Sig0>
0215 {
0216 };
0217 
0218 template <typename Sig0, typename... SigN>
0219 struct are_any_lvalue_completion_signatures<Sig0, SigN...>
0220   : integral_constant<bool, (
0221       is_lvalue_completion_signature<Sig0>::value
0222         || are_any_lvalue_completion_signatures<SigN...>::value)>
0223 {
0224 };
0225 
0226 template <typename T>
0227 struct is_rvalue_completion_signature : false_type
0228 {
0229 };
0230 
0231 template <typename R, typename... Args>
0232 struct is_rvalue_completion_signature<R(Args...) &&> : true_type
0233 {
0234 };
0235 
0236 # if defined(BOOST_ASIO_HAS_NOEXCEPT_FUNCTION_TYPE)
0237 
0238 template <typename R, typename... Args>
0239 struct is_rvalue_completion_signature<R(Args...) && noexcept> : true_type
0240 {
0241 };
0242 
0243 # endif // defined(BOOST_ASIO_HAS_NOEXCEPT_FUNCTION_TYPE)
0244 
0245 template <typename... Signatures>
0246 struct are_any_rvalue_completion_signatures : false_type
0247 {
0248 };
0249 
0250 template <typename Sig0>
0251 struct are_any_rvalue_completion_signatures<Sig0>
0252   : is_rvalue_completion_signature<Sig0>
0253 {
0254 };
0255 
0256 template <typename Sig0, typename... SigN>
0257 struct are_any_rvalue_completion_signatures<Sig0, SigN...>
0258   : integral_constant<bool, (
0259       is_rvalue_completion_signature<Sig0>::value
0260         || are_any_rvalue_completion_signatures<SigN...>::value)>
0261 {
0262 };
0263 
0264 template <typename T>
0265 struct simple_completion_signature;
0266 
0267 template <typename R, typename... Args>
0268 struct simple_completion_signature<R(Args...)>
0269 {
0270   typedef R type(Args...);
0271 };
0272 
0273 template <typename R, typename... Args>
0274 struct simple_completion_signature<R(Args...) &>
0275 {
0276   typedef R type(Args...);
0277 };
0278 
0279 template <typename R, typename... Args>
0280 struct simple_completion_signature<R(Args...) &&>
0281 {
0282   typedef R type(Args...);
0283 };
0284 
0285 # if defined(BOOST_ASIO_HAS_NOEXCEPT_FUNCTION_TYPE)
0286 
0287 template <typename R, typename... Args>
0288 struct simple_completion_signature<R(Args...) noexcept>
0289 {
0290   typedef R type(Args...);
0291 };
0292 
0293 template <typename R, typename... Args>
0294 struct simple_completion_signature<R(Args...) & noexcept>
0295 {
0296   typedef R type(Args...);
0297 };
0298 
0299 template <typename R, typename... Args>
0300 struct simple_completion_signature<R(Args...) && noexcept>
0301 {
0302   typedef R type(Args...);
0303 };
0304 
0305 # endif // defined(BOOST_ASIO_HAS_NOEXCEPT_FUNCTION_TYPE)
0306 
0307 template <typename CompletionToken,
0308     BOOST_ASIO_COMPLETION_SIGNATURE... Signatures>
0309 class completion_handler_async_result
0310 {
0311 public:
0312   typedef CompletionToken completion_handler_type;
0313   typedef void return_type;
0314 
0315   explicit completion_handler_async_result(completion_handler_type&)
0316   {
0317   }
0318 
0319   return_type get()
0320   {
0321   }
0322 
0323   template <typename Initiation,
0324       BOOST_ASIO_COMPLETION_HANDLER_FOR(Signatures...) RawCompletionToken,
0325       typename... Args>
0326   static return_type initiate(Initiation&& initiation,
0327       RawCompletionToken&& token, Args&&... args)
0328   {
0329     static_cast<Initiation&&>(initiation)(
0330         static_cast<RawCompletionToken&&>(token),
0331         static_cast<Args&&>(args)...);
0332   }
0333 
0334 private:
0335   completion_handler_async_result(
0336       const completion_handler_async_result&) = delete;
0337   completion_handler_async_result& operator=(
0338       const completion_handler_async_result&) = delete;
0339 };
0340 
0341 } // namespace detail
0342 
0343 #if defined(GENERATING_DOCUMENTATION)
0344 
0345 /// An interface for customising the behaviour of an initiating function.
0346 /**
0347  * The async_result trait is a customisation point that is used within the
0348  * initiating function for an @ref asynchronous_operation. The trait combines:
0349  *
0350  * @li the completion signature (or signatures) that describe the arguments that
0351  * an asynchronous operation will pass to a completion handler;
0352  *
0353  * @li the @ref completion_token type supplied by the caller; and
0354  *
0355  * @li the operation's internal implementation.
0356  *
0357  * Specialisations of the trait must satisfy the @ref async_result_requirements,
0358  * and are reponsible for determining:
0359  *
0360  * @li the concrete completion handler type to be called at the end of the
0361  * asynchronous operation;
0362  *
0363  * @li the initiating function return type;
0364  *
0365  * @li how the return value of the initiating function is obtained; and
0366  *
0367  * @li how and when to launch the operation by invoking the supplied initiation
0368  * function object.
0369  *
0370  * This template may be specialised for user-defined completion token types.
0371  * The primary template assumes that the CompletionToken is the already a
0372  * concrete completion handler.
0373  *
0374  * @note For backwards compatibility, the primary template implements member
0375  * types and functions that are associated with legacy forms of the async_result
0376  * trait. These are annotated as "Legacy" in the documentation below. User
0377  * specialisations of this trait do not need to implement these in order to
0378  * satisfy the @ref async_result_requirements.
0379  *
0380  * In general, implementers of asynchronous operations should use the
0381  * async_initiate function rather than using the async_result trait directly.
0382  */
0383 template <typename CompletionToken,
0384     BOOST_ASIO_COMPLETION_SIGNATURE... Signatures>
0385 class async_result
0386 {
0387 public:
0388   /// (Legacy.) The concrete completion handler type for the specific signature.
0389   typedef CompletionToken completion_handler_type;
0390 
0391   /// (Legacy.) The return type of the initiating function.
0392   typedef void return_type;
0393 
0394   /// (Legacy.) Construct an async result from a given handler.
0395   /**
0396    * When using a specalised async_result, the constructor has an opportunity
0397    * to initialise some state associated with the completion handler, which is
0398    * then returned from the initiating function.
0399    */
0400   explicit async_result(completion_handler_type& h);
0401 
0402   /// (Legacy.) Obtain the value to be returned from the initiating function.
0403   return_type get();
0404 
0405   /// Initiate the asynchronous operation that will produce the result, and
0406   /// obtain the value to be returned from the initiating function.
0407   template <typename Initiation, typename RawCompletionToken, typename... Args>
0408   static return_type initiate(
0409       Initiation&& initiation,
0410       RawCompletionToken&& token,
0411       Args&&... args);
0412 
0413 private:
0414   async_result(const async_result&) = delete;
0415   async_result& operator=(const async_result&) = delete;
0416 };
0417 
0418 #else // defined(GENERATING_DOCUMENTATION)
0419 
0420 template <typename CompletionToken,
0421     BOOST_ASIO_COMPLETION_SIGNATURE... Signatures>
0422 class async_result :
0423   public conditional_t<
0424       detail::are_any_lvalue_completion_signatures<Signatures...>::value
0425         || !detail::are_any_rvalue_completion_signatures<Signatures...>::value,
0426       detail::completion_handler_async_result<CompletionToken, Signatures...>,
0427       async_result<CompletionToken,
0428         typename detail::simple_completion_signature<Signatures>::type...>
0429     >
0430 {
0431 public:
0432   typedef conditional_t<
0433       detail::are_any_lvalue_completion_signatures<Signatures...>::value
0434         || !detail::are_any_rvalue_completion_signatures<Signatures...>::value,
0435       detail::completion_handler_async_result<CompletionToken, Signatures...>,
0436       async_result<CompletionToken,
0437         typename detail::simple_completion_signature<Signatures>::type...>
0438     > base_type;
0439 
0440   using base_type::base_type;
0441 
0442 private:
0443   async_result(const async_result&) = delete;
0444   async_result& operator=(const async_result&) = delete;
0445 };
0446 
0447 template <BOOST_ASIO_COMPLETION_SIGNATURE... Signatures>
0448 class async_result<void, Signatures...>
0449 {
0450   // Empty.
0451 };
0452 
0453 #endif // defined(GENERATING_DOCUMENTATION)
0454 
0455 /// Helper template to deduce the handler type from a CompletionToken, capture
0456 /// a local copy of the handler, and then create an async_result for the
0457 /// handler.
0458 template <typename CompletionToken,
0459     BOOST_ASIO_COMPLETION_SIGNATURE... Signatures>
0460 struct async_completion
0461 {
0462   /// The real handler type to be used for the asynchronous operation.
0463   typedef typename boost::asio::async_result<
0464     decay_t<CompletionToken>, Signatures...>::completion_handler_type
0465       completion_handler_type;
0466 
0467   /// Constructor.
0468   /**
0469    * The constructor creates the concrete completion handler and makes the link
0470    * between the handler and the asynchronous result.
0471    */
0472   explicit async_completion(CompletionToken& token)
0473     : completion_handler(static_cast<conditional_t<
0474         is_same<CompletionToken, completion_handler_type>::value,
0475         completion_handler_type&, CompletionToken&&>>(token)),
0476       result(completion_handler)
0477   {
0478   }
0479 
0480   /// A copy of, or reference to, a real handler object.
0481   conditional_t<
0482     is_same<CompletionToken, completion_handler_type>::value,
0483     completion_handler_type&, completion_handler_type> completion_handler;
0484 
0485   /// The result of the asynchronous operation's initiating function.
0486   async_result<decay_t<CompletionToken>, Signatures...> result;
0487 };
0488 
0489 namespace detail {
0490 
0491 struct async_result_memfns_base
0492 {
0493   void initiate();
0494 };
0495 
0496 template <typename T>
0497 struct async_result_memfns_derived
0498   : T, async_result_memfns_base
0499 {
0500 };
0501 
0502 template <typename T, T>
0503 struct async_result_memfns_check
0504 {
0505 };
0506 
0507 template <typename>
0508 char (&async_result_initiate_memfn_helper(...))[2];
0509 
0510 template <typename T>
0511 char async_result_initiate_memfn_helper(
0512     async_result_memfns_check<
0513       void (async_result_memfns_base::*)(),
0514       &async_result_memfns_derived<T>::initiate>*);
0515 
0516 template <typename CompletionToken,
0517     BOOST_ASIO_COMPLETION_SIGNATURE... Signatures>
0518 struct async_result_has_initiate_memfn
0519   : integral_constant<bool, sizeof(async_result_initiate_memfn_helper<
0520       async_result<decay_t<CompletionToken>, Signatures...>
0521     >(0)) != 1>
0522 {
0523 };
0524 
0525 } // namespace detail
0526 
0527 #if defined(GENERATING_DOCUMENTATION)
0528 # define BOOST_ASIO_INITFN_RESULT_TYPE(ct, sig) \
0529   void_or_deduced
0530 # define BOOST_ASIO_INITFN_RESULT_TYPE2(ct, sig0, sig1) \
0531   void_or_deduced
0532 # define BOOST_ASIO_INITFN_RESULT_TYPE3(ct, sig0, sig1, sig2) \
0533   void_or_deduced
0534 #else
0535 # define BOOST_ASIO_INITFN_RESULT_TYPE(ct, sig) \
0536   typename ::boost::asio::async_result< \
0537     typename ::boost::asio::decay<ct>::type, sig>::return_type
0538 # define BOOST_ASIO_INITFN_RESULT_TYPE2(ct, sig0, sig1) \
0539   typename ::boost::asio::async_result< \
0540     typename ::boost::asio::decay<ct>::type, sig0, sig1>::return_type
0541 # define BOOST_ASIO_INITFN_RESULT_TYPE3(ct, sig0, sig1, sig2) \
0542   typename ::boost::asio::async_result< \
0543     typename ::boost::asio::decay<ct>::type, sig0, sig1, sig2>::return_type
0544 #define BOOST_ASIO_HANDLER_TYPE(ct, sig) \
0545   typename ::boost::asio::async_result< \
0546     typename ::boost::asio::decay<ct>::type, sig>::completion_handler_type
0547 #define BOOST_ASIO_HANDLER_TYPE2(ct, sig0, sig1) \
0548   typename ::boost::asio::async_result< \
0549     typename ::boost::asio::decay<ct>::type, \
0550       sig0, sig1>::completion_handler_type
0551 #define BOOST_ASIO_HANDLER_TYPE3(ct, sig0, sig1, sig2) \
0552   typename ::boost::asio::async_result< \
0553     typename ::boost::asio::decay<ct>::type, \
0554       sig0, sig1, sig2>::completion_handler_type
0555 #endif
0556 
0557 #if defined(GENERATING_DOCUMENTATION)
0558 # define BOOST_ASIO_INITFN_AUTO_RESULT_TYPE(ct, sig) \
0559   auto
0560 # define BOOST_ASIO_INITFN_AUTO_RESULT_TYPE2(ct, sig0, sig1) \
0561   auto
0562 # define BOOST_ASIO_INITFN_AUTO_RESULT_TYPE3(ct, sig0, sig1, sig2) \
0563   auto
0564 #elif defined(BOOST_ASIO_HAS_RETURN_TYPE_DEDUCTION)
0565 # define BOOST_ASIO_INITFN_AUTO_RESULT_TYPE(ct, sig) \
0566   auto
0567 # define BOOST_ASIO_INITFN_AUTO_RESULT_TYPE2(ct, sig0, sig1) \
0568   auto
0569 # define BOOST_ASIO_INITFN_AUTO_RESULT_TYPE3(ct, sig0, sig1, sig2) \
0570   auto
0571 #else
0572 # define BOOST_ASIO_INITFN_AUTO_RESULT_TYPE(ct, sig) \
0573   BOOST_ASIO_INITFN_RESULT_TYPE(ct, sig)
0574 # define BOOST_ASIO_INITFN_AUTO_RESULT_TYPE2(ct, sig0, sig1) \
0575   BOOST_ASIO_INITFN_RESULT_TYPE2(ct, sig0, sig1)
0576 # define BOOST_ASIO_INITFN_AUTO_RESULT_TYPE3(ct, sig0, sig1, sig2) \
0577   BOOST_ASIO_INITFN_RESULT_TYPE3(ct, sig0, sig1, sig2)
0578 #endif
0579 
0580 #if defined(GENERATING_DOCUMENTATION)
0581 # define BOOST_ASIO_INITFN_AUTO_RESULT_TYPE_PREFIX(ct, sig) \
0582   auto
0583 # define BOOST_ASIO_INITFN_AUTO_RESULT_TYPE_PREFIX2(ct, sig0, sig1) \
0584   auto
0585 # define BOOST_ASIO_INITFN_AUTO_RESULT_TYPE_PREFIX3(ct, sig0, sig1, sig2) \
0586   auto
0587 # define BOOST_ASIO_INITFN_AUTO_RESULT_TYPE_SUFFIX(expr)
0588 #elif defined(BOOST_ASIO_HAS_RETURN_TYPE_DEDUCTION)
0589 # define BOOST_ASIO_INITFN_AUTO_RESULT_TYPE_PREFIX(ct, sig) \
0590   auto
0591 # define BOOST_ASIO_INITFN_AUTO_RESULT_TYPE_PREFIX2(ct, sig0, sig1) \
0592   auto
0593 # define BOOST_ASIO_INITFN_AUTO_RESULT_TYPE_PREFIX3(ct, sig0, sig1, sig2) \
0594   auto
0595 # define BOOST_ASIO_INITFN_AUTO_RESULT_TYPE_SUFFIX(expr)
0596 #else
0597 # define BOOST_ASIO_INITFN_AUTO_RESULT_TYPE_PREFIX(ct, sig) \
0598   auto
0599 # define BOOST_ASIO_INITFN_AUTO_RESULT_TYPE_PREFIX2(ct, sig0, sig1) \
0600   auto
0601 # define BOOST_ASIO_INITFN_AUTO_RESULT_TYPE_PREFIX3(ct, sig0, sig1, sig2) \
0602   auto
0603 # define BOOST_ASIO_INITFN_AUTO_RESULT_TYPE_SUFFIX(expr) -> decltype expr
0604 #endif
0605 
0606 #if defined(GENERATING_DOCUMENTATION)
0607 # define BOOST_ASIO_INITFN_DEDUCED_RESULT_TYPE(ct, sig, expr) \
0608   void_or_deduced
0609 # define BOOST_ASIO_INITFN_DEDUCED_RESULT_TYPE2(ct, sig0, sig1, expr) \
0610   void_or_deduced
0611 # define BOOST_ASIO_INITFN_DEDUCED_RESULT_TYPE3(ct, sig0, sig1, sig2, expr) \
0612   void_or_deduced
0613 #else
0614 # define BOOST_ASIO_INITFN_DEDUCED_RESULT_TYPE(ct, sig, expr) \
0615   decltype expr
0616 # define BOOST_ASIO_INITFN_DEDUCED_RESULT_TYPE2(ct, sig0, sig1, expr) \
0617   decltype expr
0618 # define BOOST_ASIO_INITFN_DEDUCED_RESULT_TYPE3(ct, sig0, sig1, sig2, expr) \
0619   decltype expr
0620 #endif
0621 
0622 #if defined(GENERATING_DOCUMENTATION)
0623 
0624 template <typename CompletionToken,
0625     completion_signature... Signatures,
0626     typename Initiation, typename... Args>
0627 void_or_deduced async_initiate(
0628     Initiation&& initiation,
0629     type_identity_t<CompletionToken>& token,
0630     Args&&... args);
0631 
0632 #else // defined(GENERATING_DOCUMENTATION)
0633 
0634 template <typename CompletionToken,
0635     BOOST_ASIO_COMPLETION_SIGNATURE... Signatures,
0636     typename Initiation, typename... Args>
0637 inline auto async_initiate(Initiation&& initiation,
0638     type_identity_t<CompletionToken>& token, Args&&... args)
0639   -> decltype(enable_if_t<
0640     enable_if_t<
0641       detail::are_completion_signatures<Signatures...>::value,
0642       detail::async_result_has_initiate_memfn<
0643         CompletionToken, Signatures...>>::value,
0644     async_result<decay_t<CompletionToken>, Signatures...>>::initiate(
0645       static_cast<Initiation&&>(initiation),
0646       static_cast<CompletionToken&&>(token),
0647       static_cast<Args&&>(args)...))
0648 {
0649   return async_result<decay_t<CompletionToken>, Signatures...>::initiate(
0650       static_cast<Initiation&&>(initiation),
0651       static_cast<CompletionToken&&>(token),
0652       static_cast<Args&&>(args)...);
0653 }
0654 
0655 template <
0656     BOOST_ASIO_COMPLETION_SIGNATURE... Signatures,
0657     typename CompletionToken, typename Initiation, typename... Args>
0658 inline auto async_initiate(Initiation&& initiation,
0659     CompletionToken&& token, Args&&... args)
0660   -> decltype(enable_if_t<
0661     enable_if_t<
0662       detail::are_completion_signatures<Signatures...>::value,
0663       detail::async_result_has_initiate_memfn<
0664         CompletionToken, Signatures...>>::value,
0665     async_result<decay_t<CompletionToken>, Signatures...>>::initiate(
0666       static_cast<Initiation&&>(initiation),
0667       static_cast<CompletionToken&&>(token),
0668       static_cast<Args&&>(args)...))
0669 {
0670   return async_result<decay_t<CompletionToken>, Signatures...>::initiate(
0671       static_cast<Initiation&&>(initiation),
0672       static_cast<CompletionToken&&>(token),
0673       static_cast<Args&&>(args)...);
0674 }
0675 
0676 template <typename CompletionToken,
0677     BOOST_ASIO_COMPLETION_SIGNATURE... Signatures,
0678     typename Initiation, typename... Args>
0679 inline typename enable_if_t<
0680     !enable_if_t<
0681       detail::are_completion_signatures<Signatures...>::value,
0682       detail::async_result_has_initiate_memfn<
0683         CompletionToken, Signatures...>>::value,
0684     async_result<decay_t<CompletionToken>, Signatures...>
0685   >::return_type
0686 async_initiate(Initiation&& initiation,
0687     type_identity_t<CompletionToken>& token, Args&&... args)
0688 {
0689   async_completion<CompletionToken, Signatures...> completion(token);
0690 
0691   static_cast<Initiation&&>(initiation)(
0692       static_cast<
0693         typename async_result<decay_t<CompletionToken>,
0694           Signatures...>::completion_handler_type&&>(
0695             completion.completion_handler),
0696       static_cast<Args&&>(args)...);
0697 
0698   return completion.result.get();
0699 }
0700 
0701 template <BOOST_ASIO_COMPLETION_SIGNATURE... Signatures,
0702     typename CompletionToken, typename Initiation, typename... Args>
0703 inline typename enable_if_t<
0704     !enable_if_t<
0705       detail::are_completion_signatures<Signatures...>::value,
0706       detail::async_result_has_initiate_memfn<
0707         CompletionToken, Signatures...>>::value,
0708     async_result<decay_t<CompletionToken>, Signatures...>
0709   >::return_type
0710 async_initiate(Initiation&& initiation, CompletionToken&& token, Args&&... args)
0711 {
0712   async_completion<CompletionToken, Signatures...> completion(token);
0713 
0714   static_cast<Initiation&&>(initiation)(
0715       static_cast<
0716         typename async_result<decay_t<CompletionToken>,
0717           Signatures...>::completion_handler_type&&>(
0718             completion.completion_handler),
0719       static_cast<Args&&>(args)...);
0720 
0721   return completion.result.get();
0722 }
0723 
0724 #endif // defined(GENERATING_DOCUMENTATION)
0725 
0726 #if defined(BOOST_ASIO_HAS_CONCEPTS)
0727 
0728 namespace detail {
0729 
0730 template <typename... Signatures>
0731 struct initiation_archetype
0732 {
0733   template <completion_handler_for<Signatures...> CompletionHandler>
0734   void operator()(CompletionHandler&&) const
0735   {
0736   }
0737 };
0738 
0739 } // namespace detail
0740 
0741 template <typename T, typename... Signatures>
0742 BOOST_ASIO_CONCEPT completion_token_for =
0743   detail::are_completion_signatures<Signatures...>::value
0744   &&
0745   requires(T&& t)
0746   {
0747     async_initiate<T, Signatures...>(
0748         detail::initiation_archetype<Signatures...>{}, t);
0749   };
0750 
0751 #define BOOST_ASIO_COMPLETION_TOKEN_FOR(sig) \
0752   ::boost::asio::completion_token_for<sig>
0753 #define BOOST_ASIO_COMPLETION_TOKEN_FOR2(sig0, sig1) \
0754   ::boost::asio::completion_token_for<sig0, sig1>
0755 #define BOOST_ASIO_COMPLETION_TOKEN_FOR3(sig0, sig1, sig2) \
0756   ::boost::asio::completion_token_for<sig0, sig1, sig2>
0757 
0758 #else // defined(BOOST_ASIO_HAS_CONCEPTS)
0759 
0760 #define BOOST_ASIO_COMPLETION_TOKEN_FOR(sig) typename
0761 #define BOOST_ASIO_COMPLETION_TOKEN_FOR2(sig0, sig1) typename
0762 #define BOOST_ASIO_COMPLETION_TOKEN_FOR3(sig0, sig1, sig2) typename
0763 
0764 #endif // defined(BOOST_ASIO_HAS_CONCEPTS)
0765 
0766 namespace detail {
0767 
0768 struct async_operation_probe {};
0769 struct async_operation_probe_result {};
0770 
0771 template <typename Call, typename = void>
0772 struct is_async_operation_call : false_type
0773 {
0774 };
0775 
0776 template <typename Call>
0777 struct is_async_operation_call<Call,
0778     void_t<
0779       enable_if_t<
0780         is_same<
0781           result_of_t<Call>,
0782           async_operation_probe_result
0783         >::value
0784       >
0785     >
0786   > : true_type
0787 {
0788 };
0789 
0790 } // namespace detail
0791 
0792 #if !defined(GENERATING_DOCUMENTATION)
0793 
0794 template <typename... Signatures>
0795 class async_result<detail::async_operation_probe, Signatures...>
0796 {
0797 public:
0798   typedef detail::async_operation_probe_result return_type;
0799 
0800   template <typename Initiation, typename... InitArgs>
0801   static return_type initiate(Initiation&&,
0802       detail::async_operation_probe, InitArgs&&...)
0803   {
0804     return return_type();
0805   }
0806 };
0807 
0808 #endif // !defined(GENERATING_DOCUMENTATION)
0809 
0810 #if defined(GENERATING_DOCUMENTATION)
0811 
0812 /// The is_async_operation trait detects whether a type @c T and arguments
0813 /// @c Args... may be used to initiate an asynchronous operation.
0814 /**
0815  * Class template @c is_async_operation is a trait is derived from @c true_type
0816  * if the expression <tt>T(Args..., token)</tt> initiates an asynchronous
0817  * operation, where @c token is an unspecified completion token type. Otherwise,
0818  * @c is_async_operation is derived from @c false_type.
0819  */
0820 template <typename T, typename... Args>
0821 struct is_async_operation : integral_constant<bool, automatically_determined>
0822 {
0823 };
0824 
0825 #else // defined(GENERATING_DOCUMENTATION)
0826 
0827 template <typename T, typename... Args>
0828 struct is_async_operation :
0829   detail::is_async_operation_call<
0830     T(Args..., detail::async_operation_probe)>
0831 {
0832 };
0833 
0834 #endif // defined(GENERATING_DOCUMENTATION)
0835 
0836 #if defined(BOOST_ASIO_HAS_CONCEPTS)
0837 
0838 template <typename T, typename... Args>
0839 BOOST_ASIO_CONCEPT async_operation = is_async_operation<T, Args...>::value;
0840 
0841 #define BOOST_ASIO_ASYNC_OPERATION \
0842   ::boost::asio::async_operation
0843 #define BOOST_ASIO_ASYNC_OPERATION1(a0) \
0844   ::boost::asio::async_operation<a0>
0845 #define BOOST_ASIO_ASYNC_OPERATION2(a0, a1) \
0846   ::boost::asio::async_operation<a0, a1>
0847 #define BOOST_ASIO_ASYNC_OPERATION3(a0, a1, a2) \
0848   ::boost::asio::async_operation<a0, a1, a2>
0849 
0850 #else // defined(BOOST_ASIO_HAS_CONCEPTS)
0851 
0852 #define BOOST_ASIO_ASYNC_OPERATION typename
0853 #define BOOST_ASIO_ASYNC_OPERATION1(a0) typename
0854 #define BOOST_ASIO_ASYNC_OPERATION2(a0, a1) typename
0855 #define BOOST_ASIO_ASYNC_OPERATION3(a0, a1, a2) typename
0856 
0857 #endif // defined(BOOST_ASIO_HAS_CONCEPTS)
0858 
0859 namespace detail {
0860 
0861 struct completion_signature_probe {};
0862 
0863 template <typename... T>
0864 struct completion_signature_probe_result
0865 {
0866   template <template <typename...> class Op>
0867   struct apply
0868   {
0869     typedef Op<T...> type;
0870   };
0871 };
0872 
0873 template <typename T>
0874 struct completion_signature_probe_result<T>
0875 {
0876   typedef T type;
0877 
0878   template <template <typename...> class Op>
0879   struct apply
0880   {
0881     typedef Op<T> type;
0882   };
0883 };
0884 
0885 template <>
0886 struct completion_signature_probe_result<void>
0887 {
0888   template <template <typename...> class Op>
0889   struct apply
0890   {
0891     typedef Op<> type;
0892   };
0893 };
0894 
0895 } // namespace detail
0896 
0897 #if !defined(GENERATING_DOCUMENTATION)
0898 
0899 template <typename... Signatures>
0900 class async_result<detail::completion_signature_probe, Signatures...>
0901 {
0902 public:
0903   typedef detail::completion_signature_probe_result<Signatures...> return_type;
0904 
0905   template <typename Initiation, typename... InitArgs>
0906   static return_type initiate(Initiation&&,
0907       detail::completion_signature_probe, InitArgs&&...)
0908   {
0909     return return_type();
0910   }
0911 };
0912 
0913 template <typename Signature>
0914 class async_result<detail::completion_signature_probe, Signature>
0915 {
0916 public:
0917   typedef detail::completion_signature_probe_result<Signature> return_type;
0918 
0919   template <typename Initiation, typename... InitArgs>
0920   static return_type initiate(Initiation&&,
0921       detail::completion_signature_probe, InitArgs&&...)
0922   {
0923     return return_type();
0924   }
0925 };
0926 
0927 #endif // !defined(GENERATING_DOCUMENTATION)
0928 
0929 #if defined(GENERATING_DOCUMENTATION)
0930 
0931 /// The completion_signature_of trait determines the completion signature
0932 /// of an asynchronous operation.
0933 /**
0934  * Class template @c completion_signature_of is a trait with a member type
0935  * alias @c type that denotes the completion signature of the asynchronous
0936  * operation initiated by the expression <tt>T(Args..., token)</tt> operation,
0937  * where @c token is an unspecified completion token type. If the asynchronous
0938  * operation does not have exactly one completion signature, the instantion of
0939  * the trait is well-formed but the member type alias @c type is omitted. If
0940  * the expression <tt>T(Args..., token)</tt> is not an asynchronous operation
0941  * then use of the trait is ill-formed.
0942  */
0943 template <typename T, typename... Args>
0944 struct completion_signature_of
0945 {
0946   typedef automatically_determined type;
0947 };
0948 
0949 #else // defined(GENERATING_DOCUMENTATION)
0950 
0951 template <typename T, typename... Args>
0952 struct completion_signature_of :
0953   result_of_t<T(Args..., detail::completion_signature_probe)>
0954 {
0955 };
0956 
0957 #endif // defined(GENERATING_DOCUMENTATION)
0958 
0959 template <typename T, typename... Args>
0960 using completion_signature_of_t =
0961   typename completion_signature_of<T, Args...>::type;
0962 
0963 } // namespace asio
0964 } // namespace boost
0965 
0966 #include <boost/asio/detail/pop_options.hpp>
0967 
0968 #include <boost/asio/default_completion_token.hpp>
0969 
0970 #endif // BOOST_ASIO_ASYNC_RESULT_HPP