File indexing completed on 2025-07-12 08:08:10
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011 #ifndef BOOST_ASIO_IMPL_APPEND_HPP
0012 #define BOOST_ASIO_IMPL_APPEND_HPP
0013
0014 #if defined(_MSC_VER) && (_MSC_VER >= 1200)
0015 # pragma once
0016 #endif
0017
0018 #include <boost/asio/detail/config.hpp>
0019 #include <boost/asio/associator.hpp>
0020 #include <boost/asio/async_result.hpp>
0021 #include <boost/asio/detail/handler_cont_helpers.hpp>
0022 #include <boost/asio/detail/initiation_base.hpp>
0023 #include <boost/asio/detail/type_traits.hpp>
0024 #include <boost/asio/detail/utility.hpp>
0025
0026 #include <boost/asio/detail/push_options.hpp>
0027
0028 namespace boost {
0029 namespace asio {
0030 namespace detail {
0031
0032
0033 template <typename Handler, typename... Values>
0034 class append_handler
0035 {
0036 public:
0037 typedef void result_type;
0038
0039 template <typename H>
0040 append_handler(H&& handler, std::tuple<Values...> values)
0041 : handler_(static_cast<H&&>(handler)),
0042 values_(static_cast<std::tuple<Values...>&&>(values))
0043 {
0044 }
0045
0046 template <typename... Args>
0047 void operator()(Args&&... args)
0048 {
0049 this->invoke(
0050 index_sequence_for<Values...>{},
0051 static_cast<Args&&>(args)...);
0052 }
0053
0054 template <std::size_t... I, typename... Args>
0055 void invoke(index_sequence<I...>, Args&&... args)
0056 {
0057 static_cast<Handler&&>(handler_)(
0058 static_cast<Args&&>(args)...,
0059 static_cast<Values&&>(std::get<I>(values_))...);
0060 }
0061
0062
0063 Handler handler_;
0064 std::tuple<Values...> values_;
0065 };
0066
0067 template <typename Handler>
0068 inline bool asio_handler_is_continuation(
0069 append_handler<Handler>* this_handler)
0070 {
0071 return boost_asio_handler_cont_helpers::is_continuation(
0072 this_handler->handler_);
0073 }
0074
0075 template <typename Signature, typename... Values>
0076 struct append_signature;
0077
0078 template <typename R, typename... Args, typename... Values>
0079 struct append_signature<R(Args...), Values...>
0080 {
0081 typedef R type(decay_t<Args>..., Values...);
0082 };
0083
0084 }
0085
0086 #if !defined(GENERATING_DOCUMENTATION)
0087
0088 template <typename CompletionToken, typename... Values, typename Signature>
0089 struct async_result<append_t<CompletionToken, Values...>, Signature>
0090 : async_result<CompletionToken,
0091 typename detail::append_signature<
0092 Signature, Values...>::type>
0093 {
0094 typedef typename detail::append_signature<
0095 Signature, Values...>::type signature;
0096
0097 template <typename Initiation>
0098 struct init_wrapper : detail::initiation_base<Initiation>
0099 {
0100 using detail::initiation_base<Initiation>::initiation_base;
0101
0102 template <typename Handler, typename... Args>
0103 void operator()(Handler&& handler,
0104 std::tuple<Values...> values, Args&&... args) &&
0105 {
0106 static_cast<Initiation&&>(*this)(
0107 detail::append_handler<decay_t<Handler>, Values...>(
0108 static_cast<Handler&&>(handler),
0109 static_cast<std::tuple<Values...>&&>(values)),
0110 static_cast<Args&&>(args)...);
0111 }
0112
0113 template <typename Handler, typename... Args>
0114 void operator()(Handler&& handler,
0115 std::tuple<Values...> values, Args&&... args) const &
0116 {
0117 static_cast<const Initiation&>(*this)(
0118 detail::append_handler<decay_t<Handler>, Values...>(
0119 static_cast<Handler&&>(handler),
0120 static_cast<std::tuple<Values...>&&>(values)),
0121 static_cast<Args&&>(args)...);
0122 }
0123 };
0124
0125 template <typename Initiation, typename RawCompletionToken, typename... Args>
0126 static auto initiate(Initiation&& initiation,
0127 RawCompletionToken&& token, Args&&... args)
0128 -> decltype(
0129 async_initiate<CompletionToken, signature>(
0130 declval<init_wrapper<decay_t<Initiation>>>(),
0131 token.token_,
0132 static_cast<std::tuple<Values...>&&>(token.values_),
0133 static_cast<Args&&>(args)...))
0134 {
0135 return async_initiate<CompletionToken, signature>(
0136 init_wrapper<decay_t<Initiation>>(
0137 static_cast<Initiation&&>(initiation)),
0138 token.token_,
0139 static_cast<std::tuple<Values...>&&>(token.values_),
0140 static_cast<Args&&>(args)...);
0141 }
0142 };
0143
0144 template <template <typename, typename> class Associator,
0145 typename Handler, typename... Values, typename DefaultCandidate>
0146 struct associator<Associator,
0147 detail::append_handler<Handler, Values...>, DefaultCandidate>
0148 : Associator<Handler, DefaultCandidate>
0149 {
0150 static typename Associator<Handler, DefaultCandidate>::type get(
0151 const detail::append_handler<Handler, Values...>& h) noexcept
0152 {
0153 return Associator<Handler, DefaultCandidate>::get(h.handler_);
0154 }
0155
0156 static auto get(const detail::append_handler<Handler, Values...>& h,
0157 const DefaultCandidate& c) noexcept
0158 -> decltype(Associator<Handler, DefaultCandidate>::get(h.handler_, c))
0159 {
0160 return Associator<Handler, DefaultCandidate>::get(h.handler_, c);
0161 }
0162 };
0163
0164 #endif
0165
0166 }
0167 }
0168
0169 #include <boost/asio/detail/pop_options.hpp>
0170
0171 #endif