// // impl/as_tuple.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 ASIO_IMPL_AS_TUPLE_HPP #define ASIO_IMPL_AS_TUPLE_HPP #if defined(_MSC_VER) && (_MSC_VER >= 1200) # pragma once #endif // defined(_MSC_VER) && (_MSC_VER >= 1200) #include "asio/detail/config.hpp" #include #include "asio/associator.hpp" #include "asio/async_result.hpp" #include "asio/detail/handler_cont_helpers.hpp" #include "asio/detail/type_traits.hpp" #include "asio/detail/push_options.hpp" namespace asio { namespace detail { // Class to adapt a as_tuple_t as a completion handler. template class as_tuple_handler { public: typedef void result_type; template as_tuple_handler(as_tuple_t e) : handler_(static_cast(e.token_)) { } template as_tuple_handler(RedirectedHandler&& h) : handler_(static_cast(h)) { } template void operator()(Args&&... args) { static_cast(handler_)( std::make_tuple(static_cast(args)...)); } //private: Handler handler_; }; template inline bool asio_handler_is_continuation( as_tuple_handler* this_handler) { return asio_handler_cont_helpers::is_continuation( this_handler->handler_); } template struct as_tuple_signature; template struct as_tuple_signature { typedef R type(std::tuple...>); }; template struct as_tuple_signature { typedef R type(std::tuple...>) &; }; template struct as_tuple_signature { typedef R type(std::tuple...>) &&; }; #if defined(ASIO_HAS_NOEXCEPT_FUNCTION_TYPE) template struct as_tuple_signature { typedef R type(std::tuple...>) noexcept; }; template struct as_tuple_signature { typedef R type(std::tuple...>) & noexcept; }; template struct as_tuple_signature { typedef R type(std::tuple...>) && noexcept; }; #endif // defined(ASIO_HAS_NOEXCEPT_FUNCTION_TYPE) } // namespace detail #if !defined(GENERATING_DOCUMENTATION) template struct async_result, Signatures...> : async_result::type...> { template struct init_wrapper { init_wrapper(Initiation init) : initiation_(static_cast(init)) { } template void operator()(Handler&& handler, Args&&... args) { static_cast(initiation_)( detail::as_tuple_handler>( static_cast(handler)), static_cast(args)...); } Initiation initiation_; }; template static auto initiate(Initiation&& initiation, RawCompletionToken&& token, Args&&... args) -> decltype( async_initiate< conditional_t< is_const>::value, const CompletionToken, CompletionToken>, typename detail::as_tuple_signature::type...>( init_wrapper>( static_cast(initiation)), token.token_, static_cast(args)...)) { return async_initiate< conditional_t< is_const>::value, const CompletionToken, CompletionToken>, typename detail::as_tuple_signature::type...>( init_wrapper>( static_cast(initiation)), token.token_, static_cast(args)...); } }; #if defined(ASIO_MSVC) // Workaround for MSVC internal compiler error. template struct async_result, Signature> : async_result::type> { template struct init_wrapper { init_wrapper(Initiation init) : initiation_(static_cast(init)) { } template void operator()(Handler&& handler, Args&&... args) { static_cast(initiation_)( detail::as_tuple_handler>( static_cast(handler)), static_cast(args)...); } Initiation initiation_; }; template static auto initiate(Initiation&& initiation, RawCompletionToken&& token, Args&&... args) -> decltype( async_initiate< conditional_t< is_const>::value, const CompletionToken, CompletionToken>, typename detail::as_tuple_signature::type>( init_wrapper>( static_cast(initiation)), token.token_, static_cast(args)...)) { return async_initiate< conditional_t< is_const>::value, const CompletionToken, CompletionToken>, typename detail::as_tuple_signature::type>( init_wrapper>( static_cast(initiation)), token.token_, static_cast(args)...); } }; #endif // defined(ASIO_MSVC) template