// // impl/append.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_APPEND_HPP #define ASIO_IMPL_APPEND_HPP #if defined(_MSC_VER) && (_MSC_VER >= 1200) # pragma once #endif // defined(_MSC_VER) && (_MSC_VER >= 1200) #include "asio/detail/config.hpp" #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/utility.hpp" #include "asio/detail/push_options.hpp" namespace asio { namespace detail { // Class to adapt an append_t as a completion handler. template class append_handler { public: typedef void result_type; template append_handler(H&& handler, std::tuple values) : handler_(static_cast(handler)), values_(static_cast&&>(values)) { } template void operator()(Args&&... args) { this->invoke( index_sequence_for{}, static_cast(args)...); } template void invoke(index_sequence, Args&&... args) { static_cast(handler_)( static_cast(args)..., static_cast(std::get(values_))...); } //private: Handler handler_; std::tuple values_; }; template inline bool asio_handler_is_continuation( append_handler* this_handler) { return asio_handler_cont_helpers::is_continuation( this_handler->handler_); } template struct append_signature; template struct append_signature { typedef R type(decay_t..., Values...); }; } // namespace detail #if !defined(GENERATING_DOCUMENTATION) template struct async_result, Signature> : async_result::type> { typedef typename detail::append_signature< Signature, Values...>::type signature; template struct init_wrapper { init_wrapper(Initiation init) : initiation_(static_cast(init)) { } template void operator()(Handler&& handler, std::tuple values, Args&&... args) { static_cast(initiation_)( detail::append_handler, Values...>( static_cast(handler), static_cast&&>(values)), static_cast(args)...); } Initiation initiation_; }; template static auto initiate(Initiation&& initiation, RawCompletionToken&& token, Args&&... args) -> decltype( async_initiate( declval>>(), token.token_, static_cast&&>(token.values_), static_cast(args)...)) { return async_initiate( init_wrapper>( static_cast(initiation)), token.token_, static_cast&&>(token.values_), static_cast(args)...); } }; template