// // impl/prepend.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_PREPEND_HPP #define ASIO_IMPL_PREPEND_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 a prepend_t as a completion handler. template class prepend_handler { public: typedef void result_type; template prepend_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(std::get(values_))..., static_cast(args)...); } //private: Handler handler_; std::tuple values_; }; template inline bool asio_handler_is_continuation( prepend_handler* this_handler) { return asio_handler_cont_helpers::is_continuation( this_handler->handler_); } template struct prepend_signature; template struct prepend_signature { typedef R type(Values..., decay_t...); }; } // namespace detail #if !defined(GENERATING_DOCUMENTATION) template struct async_result< prepend_t, Signature> : async_result::type> { typedef typename detail::prepend_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::prepend_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