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