// // impl/append.hpp // ~~~~~~~~~~~~~~~ // // Copyright (c) 2003-2023 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_APPEND_HPP #define BOOST_ASIO_IMPL_APPEND_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 #include #include namespace boost { 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(BOOST_ASIO_MOVE_ARG(H) handler, std::tuple values) : handler_(BOOST_ASIO_MOVE_CAST(H)(handler)), values_(BOOST_ASIO_MOVE_CAST(std::tuple)(values)) { } template void operator()(BOOST_ASIO_MOVE_ARG(Args)... args) { this->invoke( index_sequence_for{}, BOOST_ASIO_MOVE_CAST(Args)(args)...); } template void invoke(index_sequence, BOOST_ASIO_MOVE_ARG(Args)... args) { BOOST_ASIO_MOVE_OR_LVALUE(Handler)(handler_)( BOOST_ASIO_MOVE_CAST(Args)(args)..., BOOST_ASIO_MOVE_CAST(Values)(std::get(values_))...); } //private: Handler handler_; std::tuple values_; }; template inline asio_handler_allocate_is_deprecated asio_handler_allocate(std::size_t size, append_handler* this_handler) { #if defined(BOOST_ASIO_NO_DEPRECATED) boost_asio_handler_alloc_helpers::allocate(size, this_handler->handler_); return asio_handler_allocate_is_no_longer_used(); #else // defined(BOOST_ASIO_NO_DEPRECATED) return boost_asio_handler_alloc_helpers::allocate( size, this_handler->handler_); #endif // defined(BOOST_ASIO_NO_DEPRECATED) } template inline asio_handler_deallocate_is_deprecated asio_handler_deallocate(void* pointer, std::size_t size, append_handler* this_handler) { boost_asio_handler_alloc_helpers::deallocate( pointer, size, this_handler->handler_); #if defined(BOOST_ASIO_NO_DEPRECATED) return asio_handler_deallocate_is_no_longer_used(); #endif // defined(BOOST_ASIO_NO_DEPRECATED) } template inline bool asio_handler_is_continuation( append_handler* this_handler) { return boost_asio_handler_cont_helpers::is_continuation( this_handler->handler_); } template inline asio_handler_invoke_is_deprecated asio_handler_invoke(Function& function, append_handler* this_handler) { boost_asio_handler_invoke_helpers::invoke( function, this_handler->handler_); #if defined(BOOST_ASIO_NO_DEPRECATED) return asio_handler_invoke_is_no_longer_used(); #endif // defined(BOOST_ASIO_NO_DEPRECATED) } template inline asio_handler_invoke_is_deprecated asio_handler_invoke(const Function& function, append_handler* this_handler) { boost_asio_handler_invoke_helpers::invoke( function, this_handler->handler_); #if defined(BOOST_ASIO_NO_DEPRECATED) return asio_handler_invoke_is_no_longer_used(); #endif // defined(BOOST_ASIO_NO_DEPRECATED) } template struct append_signature; template struct append_signature { typedef R type(typename decay::type..., Values...); }; } // namespace detail #if !defined(GENERATING_DOCUMENTATION) template struct async_result< append_t, Signature> : async_result::type> { typedef typename detail::append_signature< Signature, Values...>::type signature; template struct init_wrapper { init_wrapper(Initiation init) : initiation_(BOOST_ASIO_MOVE_CAST(Initiation)(init)) { } template void operator()( BOOST_ASIO_MOVE_ARG(Handler) handler, std::tuple values, BOOST_ASIO_MOVE_ARG(Args)... args) { BOOST_ASIO_MOVE_CAST(Initiation)(initiation_)( detail::append_handler< typename decay::type, Values...>( BOOST_ASIO_MOVE_CAST(Handler)(handler), BOOST_ASIO_MOVE_CAST(std::tuple)(values)), BOOST_ASIO_MOVE_CAST(Args)(args)...); } Initiation initiation_; }; template static BOOST_ASIO_INITFN_DEDUCED_RESULT_TYPE(CompletionToken, signature, (async_initiate( declval::type> >(), declval(), declval >(), declval()...))) initiate( BOOST_ASIO_MOVE_ARG(Initiation) initiation, BOOST_ASIO_MOVE_ARG(RawCompletionToken) token, BOOST_ASIO_MOVE_ARG(Args)... args) { return async_initiate( init_wrapper::type>( BOOST_ASIO_MOVE_CAST(Initiation)(initiation)), token.token_, BOOST_ASIO_MOVE_CAST(std::tuple)(token.values_), BOOST_ASIO_MOVE_CAST(Args)(args)...); } }; template