// // async_result.hpp // ~~~~~~~~~~~~~~~~ // // Copyright (c) 2003-2021 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 #include #include #include namespace boost { namespace asio { #if defined(BOOST_ASIO_HAS_CONCEPTS) \ && defined(BOOST_ASIO_HAS_VARIADIC_TEMPLATES) \ && defined(BOOST_ASIO_HAS_DECLTYPE) namespace detail { template struct is_completion_signature : false_type { }; template struct is_completion_signature : true_type { }; #if defined(BOOST_ASIO_HAS_REF_QUALIFIED_FUNCTIONS) template struct is_completion_signature : true_type { }; template struct is_completion_signature : true_type { }; # if defined(BOOST_ASIO_HAS_NOEXCEPT_FUNCTION_TYPE) template struct is_completion_signature : true_type { }; template struct is_completion_signature : true_type { }; template struct is_completion_signature : true_type { }; # endif // defined(BOOST_ASIO_HAS_NOEXCEPT_FUNCTION_TYPE) #endif // defined(BOOST_ASIO_HAS_REF_QUALIFIED_FUNCTIONS) template struct are_completion_signatures : false_type { }; template struct are_completion_signatures : is_completion_signature { }; template struct are_completion_signatures : integral_constant::value && are_completion_signatures::value)> { }; template BOOST_ASIO_CONCEPT callable_with = requires(T&& t, Args&&... args) { static_cast(t)(static_cast(args)...); }; template struct is_completion_handler_for : false_type { }; template struct is_completion_handler_for : integral_constant)> { }; #if defined(BOOST_ASIO_HAS_REF_QUALIFIED_FUNCTIONS) template struct is_completion_handler_for : integral_constant)> { }; template struct is_completion_handler_for : integral_constant)> { }; # if defined(BOOST_ASIO_HAS_NOEXCEPT_FUNCTION_TYPE) template struct is_completion_handler_for : integral_constant)> { }; template struct is_completion_handler_for : integral_constant)> { }; template struct is_completion_handler_for : integral_constant)> { }; # endif // defined(BOOST_ASIO_HAS_NOEXCEPT_FUNCTION_TYPE) #endif // defined(BOOST_ASIO_HAS_REF_QUALIFIED_FUNCTIONS) template struct is_completion_handler_for : integral_constant::value && is_completion_handler_for::value)> { }; } // namespace detail template BOOST_ASIO_CONCEPT completion_signature = detail::is_completion_signature::value; #define BOOST_ASIO_COMPLETION_SIGNATURE \ ::boost::asio::completion_signature template BOOST_ASIO_CONCEPT completion_handler_for = detail::are_completion_signatures::value && detail::is_completion_handler_for::value; #define BOOST_ASIO_COMPLETION_HANDLER_FOR(sig) \ ::boost::asio::completion_handler_for #define BOOST_ASIO_COMPLETION_HANDLER_FOR2(sig0, sig1) \ ::boost::asio::completion_handler_for #define BOOST_ASIO_COMPLETION_HANDLER_FOR3(sig0, sig1, sig2) \ ::boost::asio::completion_handler_for #else // defined(BOOST_ASIO_HAS_CONCEPTS) // && defined(BOOST_ASIO_HAS_VARIADIC_TEMPLATES) // && defined(BOOST_ASIO_HAS_DECLTYPE) #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) // && defined(BOOST_ASIO_HAS_VARIADIC_TEMPLATES) // && defined(BOOST_ASIO_HAS_DECLTYPE) namespace detail { template struct is_simple_completion_signature : false_type { }; template struct simple_completion_signature; #if defined(BOOST_ASIO_HAS_VARIADIC_TEMPLATES) template struct is_simple_completion_signature : true_type { }; template struct are_simple_completion_signatures : false_type { }; template struct are_simple_completion_signatures : is_simple_completion_signature { }; template struct are_simple_completion_signatures : integral_constant::value && are_simple_completion_signatures::value)> { }; template struct simple_completion_signature { typedef R type(Args...); }; #if defined(BOOST_ASIO_HAS_REF_QUALIFIED_FUNCTIONS) template struct simple_completion_signature { typedef R type(Args...); }; template struct simple_completion_signature { typedef R type(Args...); }; # if defined(BOOST_ASIO_HAS_NOEXCEPT_FUNCTION_TYPE) template struct simple_completion_signature { typedef R type(Args...); }; template struct simple_completion_signature { typedef R type(Args...); }; template struct simple_completion_signature { typedef R type(Args...); }; # endif // defined(BOOST_ASIO_HAS_NOEXCEPT_FUNCTION_TYPE) #endif // defined(BOOST_ASIO_HAS_REF_QUALIFIED_FUNCTIONS) #else // defined(BOOST_ASIO_HAS_VARIADIC_TEMPLATES) template struct is_simple_completion_signature : true_type { }; #define BOOST_ASIO_PRIVATE_SIMPLE_SIG_DEF(n) \ template \ struct is_simple_completion_signature \ : true_type \ { \ }; \ /**/ BOOST_ASIO_VARIADIC_GENERATE(BOOST_ASIO_PRIVATE_SIMPLE_SIG_DEF) #undef BOOST_ASIO_PRIVATE_SIMPLE_SIG_DEF template struct are_simple_completion_signatures : false_type { }; template struct are_simple_completion_signatures : is_simple_completion_signature { }; template struct are_simple_completion_signatures : integral_constant::value && is_simple_completion_signature::value)> { }; template struct are_simple_completion_signatures : integral_constant::value && is_simple_completion_signature::value && is_simple_completion_signature::value)> { }; template <> struct simple_completion_signature { typedef void type; }; template struct simple_completion_signature { typedef R type(); }; #define BOOST_ASIO_PRIVATE_SIMPLE_SIG_DEF(n) \ template \ struct simple_completion_signature \ { \ typedef R type(BOOST_ASIO_VARIADIC_TARGS(n)); \ }; \ /**/ BOOST_ASIO_VARIADIC_GENERATE(BOOST_ASIO_PRIVATE_SIMPLE_SIG_DEF) #undef BOOST_ASIO_PRIVATE_SIMPLE_SIG_DEF #if defined(BOOST_ASIO_HAS_REF_QUALIFIED_FUNCTIONS) template struct simple_completion_signature { typedef R type(); }; template struct simple_completion_signature { typedef R type(); }; #define BOOST_ASIO_PRIVATE_SIMPLE_SIG_DEF(n) \ template \ struct simple_completion_signature< \ R(BOOST_ASIO_VARIADIC_TARGS(n)) &> \ { \ typedef R type(BOOST_ASIO_VARIADIC_TARGS(n)); \ }; \ \ template \ struct simple_completion_signature< \ R(BOOST_ASIO_VARIADIC_TARGS(n)) &&> \ { \ typedef R type(BOOST_ASIO_VARIADIC_TARGS(n)); \ }; \ /**/ BOOST_ASIO_VARIADIC_GENERATE(BOOST_ASIO_PRIVATE_SIMPLE_SIG_DEF) #undef BOOST_ASIO_PRIVATE_SIMPLE_SIG_DEF # if defined(BOOST_ASIO_HAS_NOEXCEPT_FUNCTION_TYPE) template struct simple_completion_signature { typedef R type(); }; template struct simple_completion_signature { typedef R type(); }; template struct simple_completion_signature { typedef R type(); }; #define BOOST_ASIO_PRIVATE_SIMPLE_SIG_DEF(n) \ template \ struct simple_completion_signature< \ R(BOOST_ASIO_VARIADIC_TARGS(n)) noexcept> \ { \ typedef R type(BOOST_ASIO_VARIADIC_TARGS(n)); \ }; \ \ template \ struct simple_completion_signature< \ R(BOOST_ASIO_VARIADIC_TARGS(n)) & noexcept> \ { \ typedef R type(BOOST_ASIO_VARIADIC_TARGS(n)); \ }; \ \ template \ struct simple_completion_signature< \ R(BOOST_ASIO_VARIADIC_TARGS(n)) && noexcept> \ { \ typedef R type(BOOST_ASIO_VARIADIC_TARGS(n)); \ }; \ /**/ BOOST_ASIO_VARIADIC_GENERATE(BOOST_ASIO_PRIVATE_SIMPLE_SIG_DEF) #undef BOOST_ASIO_PRIVATE_SIMPLE_SIG_DEF # endif // defined(BOOST_ASIO_HAS_NOEXCEPT_FUNCTION_TYPE) #endif // defined(BOOST_ASIO_HAS_REF_QUALIFIED_FUNCTIONS) #endif // defined(BOOST_ASIO_HAS_VARIADIC_TEMPLATES) #if defined(BOOST_ASIO_HAS_VARIADIC_TEMPLATES) \ || defined(GENERATING_DOCUMENTATION) # define BOOST_ASIO_COMPLETION_SIGNATURES_TPARAMS \ BOOST_ASIO_COMPLETION_SIGNATURE... Signatures # define BOOST_ASIO_COMPLETION_SIGNATURES_TSPECPARAMS \ BOOST_ASIO_COMPLETION_SIGNATURE... Signatures # define BOOST_ASIO_COMPLETION_SIGNATURES_TARGS Signatures... # define BOOST_ASIO_COMPLETION_SIGNATURES_TSIMPLEARGS \ typename boost::asio::detail::simple_completion_signature< \ Signatures>::type... #else // defined(BOOST_ASIO_HAS_VARIADIC_TEMPLATES) // || defined(GENERATING_DOCUMENTATION) # define BOOST_ASIO_COMPLETION_SIGNATURES_TPARAMS \ typename Sig0 = void, \ typename Sig1 = void, \ typename Sig2 = void # define BOOST_ASIO_COMPLETION_SIGNATURES_TSPECPARAMS \ typename Sig0, \ typename Sig1, \ typename Sig2 # define BOOST_ASIO_COMPLETION_SIGNATURES_TARGS Sig0, Sig1, Sig2 # define BOOST_ASIO_COMPLETION_SIGNATURES_TSIMPLEARGS \ typename ::boost::asio::detail::simple_completion_signature::type, \ typename ::boost::asio::detail::simple_completion_signature::type, \ typename ::boost::asio::detail::simple_completion_signature::type #endif // defined(BOOST_ASIO_HAS_VARIADIC_TEMPLATES) // || defined(GENERATING_DOCUMENTATION) template 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() { } #if defined(BOOST_ASIO_HAS_VARIADIC_TEMPLATES) template static return_type initiate( BOOST_ASIO_MOVE_ARG(Initiation) initiation, BOOST_ASIO_MOVE_ARG(RawCompletionToken) token, BOOST_ASIO_MOVE_ARG(Args)... args) { BOOST_ASIO_MOVE_CAST(Initiation)(initiation)( BOOST_ASIO_MOVE_CAST(RawCompletionToken)(token), BOOST_ASIO_MOVE_CAST(Args)(args)...); } #else // defined(BOOST_ASIO_HAS_VARIADIC_TEMPLATES) template static return_type initiate( BOOST_ASIO_MOVE_ARG(Initiation) initiation, BOOST_ASIO_MOVE_ARG(RawCompletionToken) token) { BOOST_ASIO_MOVE_CAST(Initiation)(initiation)( BOOST_ASIO_MOVE_CAST(RawCompletionToken)(token)); } #define BOOST_ASIO_PRIVATE_INITIATE_DEF(n) \ template \ static return_type initiate( \ BOOST_ASIO_MOVE_ARG(Initiation) initiation, \ BOOST_ASIO_MOVE_ARG(RawCompletionToken) token, \ BOOST_ASIO_VARIADIC_MOVE_PARAMS(n)) \ { \ BOOST_ASIO_MOVE_CAST(Initiation)(initiation)( \ BOOST_ASIO_MOVE_CAST(RawCompletionToken)(token), \ BOOST_ASIO_VARIADIC_MOVE_ARGS(n)); \ } \ /**/ BOOST_ASIO_VARIADIC_GENERATE(BOOST_ASIO_PRIVATE_INITIATE_DEF) #undef BOOST_ASIO_PRIVATE_INITIATE_DEF #endif // defined(BOOST_ASIO_HAS_VARIADIC_TEMPLATES) private: completion_handler_async_result( const completion_handler_async_result&) BOOST_ASIO_DELETED; completion_handler_async_result& operator=( const completion_handler_async_result&) BOOST_ASIO_DELETED; }; } // 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 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 static return_type initiate( BOOST_ASIO_MOVE_ARG(Initiation) initiation, BOOST_ASIO_MOVE_ARG(RawCompletionToken) token, BOOST_ASIO_MOVE_ARG(Args)... args); private: async_result(const async_result&) BOOST_ASIO_DELETED; async_result& operator=(const async_result&) BOOST_ASIO_DELETED; }; #else // defined(GENERATING_DOCUMENTATION) #if defined(BOOST_ASIO_HAS_REF_QUALIFIED_FUNCTIONS) template class async_result : public conditional< detail::are_simple_completion_signatures< BOOST_ASIO_COMPLETION_SIGNATURES_TARGS>::value, detail::completion_handler_async_result< CompletionToken, BOOST_ASIO_COMPLETION_SIGNATURES_TARGS>, async_result >::type { public: typedef typename conditional< detail::are_simple_completion_signatures< BOOST_ASIO_COMPLETION_SIGNATURES_TARGS>::value, detail::completion_handler_async_result< CompletionToken, BOOST_ASIO_COMPLETION_SIGNATURES_TARGS>, async_result >::type base_type; using base_type::base_type; private: async_result(const async_result&) BOOST_ASIO_DELETED; async_result& operator=(const async_result&) BOOST_ASIO_DELETED; }; #else // defined(BOOST_ASIO_HAS_REF_QUALIFIED_FUNCTIONS) template class async_result : public detail::completion_handler_async_result< CompletionToken, BOOST_ASIO_COMPLETION_SIGNATURES_TARGS> { public: explicit async_result(CompletionToken& h) : detail::completion_handler_async_result< CompletionToken, BOOST_ASIO_COMPLETION_SIGNATURES_TARGS>(h) { } private: async_result(const async_result&) BOOST_ASIO_DELETED; async_result& operator=(const async_result&) BOOST_ASIO_DELETED; }; #endif // defined(BOOST_ASIO_HAS_REF_QUALIFIED_FUNCTIONS) template class async_result { // 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 struct async_completion { /// The real handler type to be used for the asynchronous operation. typedef typename boost::asio::async_result< typename decay::type, BOOST_ASIO_COMPLETION_SIGNATURES_TARGS>::completion_handler_type completion_handler_type; #if defined(BOOST_ASIO_HAS_MOVE) || defined(GENERATING_DOCUMENTATION) /// 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::value, completion_handler_type&, CompletionToken&&>::type>(token)), result(completion_handler) { } #else // defined(BOOST_ASIO_HAS_MOVE) || defined(GENERATING_DOCUMENTATION) explicit async_completion(typename decay::type& token) : completion_handler(token), result(completion_handler) { } explicit async_completion(const typename decay::type& token) : completion_handler(token), result(completion_handler) { } #endif // defined(BOOST_ASIO_HAS_MOVE) || defined(GENERATING_DOCUMENTATION) /// A copy of, or reference to, a real handler object. #if defined(BOOST_ASIO_HAS_MOVE) || defined(GENERATING_DOCUMENTATION) typename conditional< is_same::value, completion_handler_type&, completion_handler_type>::type completion_handler; #else // defined(BOOST_ASIO_HAS_MOVE) || defined(GENERATING_DOCUMENTATION) completion_handler_type completion_handler; #endif // defined(BOOST_ASIO_HAS_MOVE) || defined(GENERATING_DOCUMENTATION) /// The result of the asynchronous operation's initiating function. async_result::type, BOOST_ASIO_COMPLETION_SIGNATURES_TARGS> result; }; namespace detail { template struct async_result_helper : async_result::type, BOOST_ASIO_COMPLETION_SIGNATURES_TARGS> { }; struct async_result_memfns_base { void initiate(); }; template struct async_result_memfns_derived : T, async_result_memfns_base { }; template struct async_result_memfns_check { }; template char (&async_result_initiate_memfn_helper(...))[2]; template char async_result_initiate_memfn_helper( async_result_memfns_check< void (async_result_memfns_base::*)(), &async_result_memfns_derived::initiate>*); template struct async_result_has_initiate_memfn : integral_constant::type, BOOST_ASIO_COMPLETION_SIGNATURES_TARGS> >(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 #elif defined(_MSC_VER) && (_MSC_VER < 1500) # define BOOST_ASIO_INITFN_RESULT_TYPE(ct, sig) \ typename ::boost::asio::detail::async_result_helper< \ ct, sig>::return_type # define BOOST_ASIO_INITFN_RESULT_TYPE2(ct, sig0, sig1) \ typename ::boost::asio::detail::async_result_helper< \ ct, sig0, sig1>::return_type # define BOOST_ASIO_INITFN_RESULT_TYPE3(ct, sig0, sig1, sig2) \ typename ::boost::asio::detail::async_result_helper< \ ct, sig0, sig1, sig2>::return_type #define BOOST_ASIO_HANDLER_TYPE(ct, sig) \ typename ::boost::asio::detail::async_result_helper< \ ct, sig>::completion_handler_type #define BOOST_ASIO_HANDLER_TYPE2(ct, sig0, sig1) \ typename ::boost::asio::detail::async_result_helper< \ ct, sig0, sig1>::completion_handler_type #define BOOST_ASIO_HANDLER_TYPE3(ct, sig0, sig1, sig2) \ typename ::boost::asio::detail::async_result_helper< \ ct, sig0, sig1, sig2>::completion_handler_type #else # define BOOST_ASIO_INITFN_RESULT_TYPE(ct, sig) \ typename ::boost::asio::async_result< \ typename ::boost::asio::decay::type, sig>::return_type # define BOOST_ASIO_INITFN_RESULT_TYPE2(ct, sig0, sig1) \ typename ::boost::asio::async_result< \ typename ::boost::asio::decay::type, sig0, sig1>::return_type # define BOOST_ASIO_INITFN_RESULT_TYPE3(ct, sig0, sig1, sig2) \ typename ::boost::asio::async_result< \ typename ::boost::asio::decay::type, sig0, sig1, sig2>::return_type #define BOOST_ASIO_HANDLER_TYPE(ct, sig) \ typename ::boost::asio::async_result< \ typename ::boost::asio::decay::type, sig>::completion_handler_type #define BOOST_ASIO_HANDLER_TYPE2(ct, sig0, sig1) \ typename ::boost::asio::async_result< \ typename ::boost::asio::decay::type, \ sig0, sig1>::completion_handler_type #define BOOST_ASIO_HANDLER_TYPE3(ct, sig0, sig1, sig2) \ typename ::boost::asio::async_result< \ typename ::boost::asio::decay::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_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 #elif defined(BOOST_ASIO_HAS_DECLTYPE) # 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 #else # define BOOST_ASIO_INITFN_DEDUCED_RESULT_TYPE(ct, sig, expr) \ BOOST_ASIO_INITFN_RESULT_TYPE(ct, sig) # define BOOST_ASIO_INITFN_DEDUCED_RESULT_TYPE2(ct, sig0, sig1, expr) \ BOOST_ASIO_INITFN_RESULT_TYPE2(ct, sig0, sig1) # define BOOST_ASIO_INITFN_DEDUCED_RESULT_TYPE3(ct, sig0, sig1, sig2, expr) \ BOOST_ASIO_INITFN_RESULT_TYPE3(ct, sig0, sig1, sig2) #endif #if defined(GENERATING_DOCUMENTATION) template void_or_deduced async_initiate( BOOST_ASIO_MOVE_ARG(Initiation) initiation, BOOST_ASIO_NONDEDUCED_MOVE_ARG(CompletionToken), BOOST_ASIO_MOVE_ARG(Args)... args); #elif defined(BOOST_ASIO_HAS_VARIADIC_TEMPLATES) template inline typename constraint< detail::async_result_has_initiate_memfn< CompletionToken, Signatures...>::value, BOOST_ASIO_INITFN_DEDUCED_RESULT_TYPE(CompletionToken, Signatures..., (async_result::type, Signatures...>::initiate(declval(), declval(), declval()...)))>::type async_initiate(BOOST_ASIO_MOVE_ARG(Initiation) initiation, BOOST_ASIO_NONDEDUCED_MOVE_ARG(CompletionToken) token, BOOST_ASIO_MOVE_ARG(Args)... args) { return async_result::type, Signatures...>::initiate(BOOST_ASIO_MOVE_CAST(Initiation)(initiation), BOOST_ASIO_MOVE_CAST(CompletionToken)(token), BOOST_ASIO_MOVE_CAST(Args)(args)...); } template inline typename constraint< !detail::async_result_has_initiate_memfn< CompletionToken, Signatures...>::value, BOOST_ASIO_INITFN_RESULT_TYPE(CompletionToken, Signatures...)>::type async_initiate(BOOST_ASIO_MOVE_ARG(Initiation) initiation, BOOST_ASIO_NONDEDUCED_MOVE_ARG(CompletionToken) token, BOOST_ASIO_MOVE_ARG(Args)... args) { async_completion completion(token); BOOST_ASIO_MOVE_CAST(Initiation)(initiation)( BOOST_ASIO_MOVE_CAST(BOOST_ASIO_HANDLER_TYPE(CompletionToken, Signatures...))(completion.completion_handler), BOOST_ASIO_MOVE_CAST(Args)(args)...); return completion.result.get(); } #else // defined(BOOST_ASIO_HAS_VARIADIC_TEMPLATES) template inline typename constraint< detail::async_result_has_initiate_memfn< CompletionToken, Sig0>::value, BOOST_ASIO_INITFN_DEDUCED_RESULT_TYPE(CompletionToken, Sig0, (async_result::type, Sig0>::initiate(declval(), declval())))>::type async_initiate(BOOST_ASIO_MOVE_ARG(Initiation) initiation, BOOST_ASIO_NONDEDUCED_MOVE_ARG(CompletionToken) token) { return async_result::type, Sig0>::initiate(BOOST_ASIO_MOVE_CAST(Initiation)(initiation), BOOST_ASIO_MOVE_CAST(CompletionToken)(token)); } template inline typename constraint< detail::async_result_has_initiate_memfn< CompletionToken, Sig0, Sig1>::value, BOOST_ASIO_INITFN_DEDUCED_RESULT_TYPE2(CompletionToken, Sig0, Sig1, (async_result::type, Sig0, Sig1>::initiate(declval(), declval())))>::type async_initiate(BOOST_ASIO_MOVE_ARG(Initiation) initiation, BOOST_ASIO_NONDEDUCED_MOVE_ARG(CompletionToken) token) { return async_result::type, Sig0, Sig1>::initiate(BOOST_ASIO_MOVE_CAST(Initiation)(initiation), BOOST_ASIO_MOVE_CAST(CompletionToken)(token)); } template inline typename constraint< detail::async_result_has_initiate_memfn< CompletionToken, Sig0, Sig1, Sig2>::value, BOOST_ASIO_INITFN_DEDUCED_RESULT_TYPE3(CompletionToken, Sig0, Sig1, Sig2, (async_result::type, Sig0, Sig1, Sig2>::initiate(declval(), declval())))>::type async_initiate(BOOST_ASIO_MOVE_ARG(Initiation) initiation, BOOST_ASIO_NONDEDUCED_MOVE_ARG(CompletionToken) token) { return async_result::type, Sig0, Sig1, Sig2>::initiate(BOOST_ASIO_MOVE_CAST(Initiation)(initiation), BOOST_ASIO_MOVE_CAST(CompletionToken)(token)); } template inline typename constraint< !detail::async_result_has_initiate_memfn< CompletionToken, Sig0>::value, BOOST_ASIO_INITFN_RESULT_TYPE(CompletionToken, Sig0)>::type async_initiate(BOOST_ASIO_MOVE_ARG(Initiation) initiation, BOOST_ASIO_NONDEDUCED_MOVE_ARG(CompletionToken) token) { async_completion completion(token); BOOST_ASIO_MOVE_CAST(Initiation)(initiation)( BOOST_ASIO_MOVE_CAST(BOOST_ASIO_HANDLER_TYPE(CompletionToken, Sig0))(completion.completion_handler)); return completion.result.get(); } template inline typename constraint< !detail::async_result_has_initiate_memfn< CompletionToken, Sig0, Sig1>::value, BOOST_ASIO_INITFN_RESULT_TYPE2(CompletionToken, Sig0, Sig1)>::type async_initiate(BOOST_ASIO_MOVE_ARG(Initiation) initiation, BOOST_ASIO_NONDEDUCED_MOVE_ARG(CompletionToken) token) { async_completion completion(token); BOOST_ASIO_MOVE_CAST(Initiation)(initiation)( BOOST_ASIO_MOVE_CAST(BOOST_ASIO_HANDLER_TYPE2(CompletionToken, Sig0, Sig1))(completion.completion_handler)); return completion.result.get(); } template inline typename constraint< !detail::async_result_has_initiate_memfn< CompletionToken, Sig0, Sig1, Sig2>::value, BOOST_ASIO_INITFN_RESULT_TYPE3(CompletionToken, Sig0, Sig1, Sig2)>::type async_initiate(BOOST_ASIO_MOVE_ARG(Initiation) initiation, BOOST_ASIO_NONDEDUCED_MOVE_ARG(CompletionToken) token) { async_completion completion(token); BOOST_ASIO_MOVE_CAST(Initiation)(initiation)( BOOST_ASIO_MOVE_CAST(BOOST_ASIO_HANDLER_TYPE3(CompletionToken, Sig0, Sig1, Sig2))(completion.completion_handler)); return completion.result.get(); } #define BOOST_ASIO_PRIVATE_INITIATE_DEF(n) \ template \ inline typename constraint< \ detail::async_result_has_initiate_memfn< \ CompletionToken, Sig0>::value, \ BOOST_ASIO_INITFN_DEDUCED_RESULT_TYPE( \ CompletionToken, Sig0, \ (async_result::type, \ Sig0>::initiate( \ declval(), \ declval(), \ BOOST_ASIO_VARIADIC_MOVE_DECLVAL(n))))>::type \ async_initiate(BOOST_ASIO_MOVE_ARG(Initiation) initiation, \ BOOST_ASIO_NONDEDUCED_MOVE_ARG(CompletionToken) token, \ BOOST_ASIO_VARIADIC_MOVE_PARAMS(n)) \ { \ return async_result::type, \ Sig0>::initiate( \ BOOST_ASIO_MOVE_CAST(Initiation)(initiation), \ BOOST_ASIO_MOVE_CAST(CompletionToken)(token), \ BOOST_ASIO_VARIADIC_MOVE_ARGS(n)); \ } \ \ template \ inline typename constraint< \ detail::async_result_has_initiate_memfn< \ CompletionToken, Sig0, Sig1>::value, \ BOOST_ASIO_INITFN_DEDUCED_RESULT_TYPE2( \ CompletionToken, Sig0, Sig1, \ (async_result::type, \ Sig0, Sig1>::initiate( \ declval(), \ declval(), \ BOOST_ASIO_VARIADIC_MOVE_DECLVAL(n))))>::type \ async_initiate(BOOST_ASIO_MOVE_ARG(Initiation) initiation, \ BOOST_ASIO_NONDEDUCED_MOVE_ARG(CompletionToken) token, \ BOOST_ASIO_VARIADIC_MOVE_PARAMS(n)) \ { \ return async_result::type, \ Sig0, Sig1>::initiate( \ BOOST_ASIO_MOVE_CAST(Initiation)(initiation), \ BOOST_ASIO_MOVE_CAST(CompletionToken)(token), \ BOOST_ASIO_VARIADIC_MOVE_ARGS(n)); \ } \ \ template \ inline typename constraint< \ detail::async_result_has_initiate_memfn< \ CompletionToken, Sig0, Sig1, Sig2>::value, \ BOOST_ASIO_INITFN_DEDUCED_RESULT_TYPE3( \ CompletionToken, Sig0, Sig1, Sig2, \ (async_result::type, \ Sig0, Sig1, Sig2>::initiate( \ declval(), \ declval(), \ BOOST_ASIO_VARIADIC_MOVE_DECLVAL(n))))>::type \ async_initiate(BOOST_ASIO_MOVE_ARG(Initiation) initiation, \ BOOST_ASIO_NONDEDUCED_MOVE_ARG(CompletionToken) token, \ BOOST_ASIO_VARIADIC_MOVE_PARAMS(n)) \ { \ return async_result::type, \ Sig0, Sig1, Sig2>::initiate( \ BOOST_ASIO_MOVE_CAST(Initiation)(initiation), \ BOOST_ASIO_MOVE_CAST(CompletionToken)(token), \ BOOST_ASIO_VARIADIC_MOVE_ARGS(n)); \ } \ \ template \ inline typename constraint< \ !detail::async_result_has_initiate_memfn< \ CompletionToken, Sig0>::value, \ BOOST_ASIO_INITFN_RESULT_TYPE(CompletionToken, Sig0)>::type \ async_initiate(BOOST_ASIO_MOVE_ARG(Initiation) initiation, \ BOOST_ASIO_NONDEDUCED_MOVE_ARG(CompletionToken) token, \ BOOST_ASIO_VARIADIC_MOVE_PARAMS(n)) \ { \ async_completion completion(token); \ \ BOOST_ASIO_MOVE_CAST(Initiation)(initiation)( \ BOOST_ASIO_MOVE_CAST(BOOST_ASIO_HANDLER_TYPE(CompletionToken, \ Sig0))(completion.completion_handler), \ BOOST_ASIO_VARIADIC_MOVE_ARGS(n)); \ \ return completion.result.get(); \ } \ \ template \ inline typename constraint< \ !detail::async_result_has_initiate_memfn< \ CompletionToken, Sig0, Sig1>::value, \ BOOST_ASIO_INITFN_RESULT_TYPE2(CompletionToken, Sig0, Sig1)>::type \ async_initiate(BOOST_ASIO_MOVE_ARG(Initiation) initiation, \ BOOST_ASIO_NONDEDUCED_MOVE_ARG(CompletionToken) token, \ BOOST_ASIO_VARIADIC_MOVE_PARAMS(n)) \ { \ async_completion completion(token); \ \ BOOST_ASIO_MOVE_CAST(Initiation)(initiation)( \ BOOST_ASIO_MOVE_CAST(BOOST_ASIO_HANDLER_TYPE2(CompletionToken, \ Sig0, Sig1))(completion.completion_handler), \ BOOST_ASIO_VARIADIC_MOVE_ARGS(n)); \ \ return completion.result.get(); \ } \ \ template \ inline typename constraint< \ !detail::async_result_has_initiate_memfn< \ CompletionToken, Sig0, Sig1, Sig2>::value, \ BOOST_ASIO_INITFN_RESULT_TYPE3(CompletionToken, Sig0, Sig1, Sig2)>::type \ async_initiate(BOOST_ASIO_MOVE_ARG(Initiation) initiation, \ BOOST_ASIO_NONDEDUCED_MOVE_ARG(CompletionToken) token, \ BOOST_ASIO_VARIADIC_MOVE_PARAMS(n)) \ { \ async_completion completion(token); \ \ BOOST_ASIO_MOVE_CAST(Initiation)(initiation)( \ BOOST_ASIO_MOVE_CAST(BOOST_ASIO_HANDLER_TYPE3(CompletionToken, \ Sig0, Sig1, Sig2))(completion.completion_handler), \ BOOST_ASIO_VARIADIC_MOVE_ARGS(n)); \ \ return completion.result.get(); \ } \ /**/ BOOST_ASIO_VARIADIC_GENERATE(BOOST_ASIO_PRIVATE_INITIATE_DEF) #undef BOOST_ASIO_PRIVATE_INITIATE_DEF #endif // defined(BOOST_ASIO_HAS_VARIADIC_TEMPLATES) #if defined(BOOST_ASIO_HAS_CONCEPTS) \ && defined(BOOST_ASIO_HAS_VARIADIC_TEMPLATES) \ && defined(BOOST_ASIO_HAS_DECLTYPE) namespace detail { template struct initiation_archetype { template CompletionHandler> void operator()(CompletionHandler&&) const { } }; } // namespace detail template BOOST_ASIO_CONCEPT completion_token_for = detail::are_completion_signatures::value && requires(T&& t) { async_initiate( detail::initiation_archetype{}, t); }; #define BOOST_ASIO_COMPLETION_TOKEN_FOR(sig) \ ::boost::asio::completion_token_for #define BOOST_ASIO_COMPLETION_TOKEN_FOR2(sig0, sig1) \ ::boost::asio::completion_token_for #define BOOST_ASIO_COMPLETION_TOKEN_FOR3(sig0, sig1, sig2) \ ::boost::asio::completion_token_for #else // defined(BOOST_ASIO_HAS_CONCEPTS) // && defined(BOOST_ASIO_HAS_VARIADIC_TEMPLATES) // && defined(BOOST_ASIO_HAS_DECLTYPE) #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) // && defined(BOOST_ASIO_HAS_VARIADIC_TEMPLATES) // && defined(BOOST_ASIO_HAS_DECLTYPE) namespace detail { template struct default_completion_token_impl { typedef void type; }; template struct default_completion_token_impl::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 struct default_completion_token { /// If @c T has a nested type @c default_completion_token_type, /// T::default_completion_token_type. Otherwise the typedef @c type /// is not defined. typedef see_below type; }; #else template struct default_completion_token : detail::default_completion_token_impl { }; #endif #if defined(BOOST_ASIO_HAS_ALIAS_TEMPLATES) template using default_completion_token_t = typename default_completion_token::type; #endif // defined(BOOST_ASIO_HAS_ALIAS_TEMPLATES) #if defined(BOOST_ASIO_HAS_DEFAULT_FUNCTION_TEMPLATE_ARGUMENTS) #define BOOST_ASIO_DEFAULT_COMPLETION_TOKEN_TYPE(e) \ = typename ::boost::asio::default_completion_token::type #define BOOST_ASIO_DEFAULT_COMPLETION_TOKEN(e) \ = typename ::boost::asio::default_completion_token::type() #else // defined(BOOST_ASIO_HAS_DEFAULT_FUNCTION_TEMPLATE_ARGUMENTS) #define BOOST_ASIO_DEFAULT_COMPLETION_TOKEN_TYPE(e) #define BOOST_ASIO_DEFAULT_COMPLETION_TOKEN(e) #endif // defined(BOOST_ASIO_HAS_DEFAULT_FUNCTION_TEMPLATE_ARGUMENTS) } // namespace asio } // namespace boost #include #endif // BOOST_ASIO_ASYNC_RESULT_HPP