// // experimental/impl/as_single.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_IMPL_EXPERIMENTAL_AS_SINGLE_HPP #define BOOST_ASIO_IMPL_EXPERIMENTAL_AS_SINGLE_HPP #if defined(_MSC_VER) && (_MSC_VER >= 1200) # pragma once #endif // defined(_MSC_VER) && (_MSC_VER >= 1200) #include #include #include #include #include #include #include #include namespace boost { namespace asio { namespace experimental { namespace detail { // Class to adapt a as_single_t as a completion handler. template class as_single_handler { public: typedef void result_type; template as_single_handler(as_single_t e) : handler_(static_cast(e.token_)) { } template as_single_handler(RedirectedHandler&& h) : handler_(static_cast(h)) { } void operator()() { static_cast(handler_)(); } template void operator()(Arg&& arg) { static_cast(handler_)(static_cast(arg)); } 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_single_handler* this_handler) { return boost_asio_handler_cont_helpers::is_continuation( this_handler->handler_); } template struct as_single_signature { typedef Signature type; }; template struct as_single_signature { typedef R type(); }; template struct as_single_signature { typedef R type(Arg); }; template struct as_single_signature { typedef R type(std::tuple...>); }; } // namespace detail } // namespace experimental #if !defined(GENERATING_DOCUMENTATION) template struct async_result, Signature> { template struct init_wrapper : detail::initiation_base { using detail::initiation_base::initiation_base; template void operator()(Handler&& handler, Args&&... args) && { static_cast(*this)( experimental::detail::as_single_handler>( static_cast(handler)), static_cast(args)...); } template void operator()(Handler&& handler, Args&&... args) const & { static_cast(*this)( experimental::detail::as_single_handler>( static_cast(handler)), static_cast(args)...); } }; template static auto initiate(Initiation&& initiation, RawCompletionToken&& token, Args&&... args) -> decltype( async_initiate::type>( init_wrapper>( static_cast(initiation)), token.token_, static_cast(args)...)) { return async_initiate::type>( init_wrapper>( static_cast(initiation)), token.token_, static_cast(args)...); } }; template