File indexing completed on 2025-01-18 09:28:51
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011 #ifndef BOOST_ASIO_IMPL_EXPERIMENTAL_AS_SINGLE_HPP
0012 #define BOOST_ASIO_IMPL_EXPERIMENTAL_AS_SINGLE_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 <tuple>
0020 #include <boost/asio/associator.hpp>
0021 #include <boost/asio/async_result.hpp>
0022 #include <boost/asio/detail/handler_cont_helpers.hpp>
0023 #include <boost/asio/detail/type_traits.hpp>
0024
0025 #include <boost/asio/detail/push_options.hpp>
0026
0027 namespace boost {
0028 namespace asio {
0029 namespace experimental {
0030 namespace detail {
0031
0032
0033 template <typename Handler>
0034 class as_single_handler
0035 {
0036 public:
0037 typedef void result_type;
0038
0039 template <typename CompletionToken>
0040 as_single_handler(as_single_t<CompletionToken> e)
0041 : handler_(static_cast<CompletionToken&&>(e.token_))
0042 {
0043 }
0044
0045 template <typename RedirectedHandler>
0046 as_single_handler(RedirectedHandler&& h)
0047 : handler_(static_cast<RedirectedHandler&&>(h))
0048 {
0049 }
0050
0051 void operator()()
0052 {
0053 static_cast<Handler&&>(handler_)();
0054 }
0055
0056 template <typename Arg>
0057 void operator()(Arg&& arg)
0058 {
0059 static_cast<Handler&&>(handler_)(static_cast<Arg&&>(arg));
0060 }
0061
0062 template <typename... Args>
0063 void operator()(Args&&... args)
0064 {
0065 static_cast<Handler&&>(handler_)(
0066 std::make_tuple(static_cast<Args&&>(args)...));
0067 }
0068
0069
0070 Handler handler_;
0071 };
0072
0073 template <typename Handler>
0074 inline bool asio_handler_is_continuation(
0075 as_single_handler<Handler>* this_handler)
0076 {
0077 return boost_asio_handler_cont_helpers::is_continuation(
0078 this_handler->handler_);
0079 }
0080
0081 template <typename Signature>
0082 struct as_single_signature
0083 {
0084 typedef Signature type;
0085 };
0086
0087 template <typename R>
0088 struct as_single_signature<R()>
0089 {
0090 typedef R type();
0091 };
0092
0093 template <typename R, typename Arg>
0094 struct as_single_signature<R(Arg)>
0095 {
0096 typedef R type(Arg);
0097 };
0098
0099 template <typename R, typename... Args>
0100 struct as_single_signature<R(Args...)>
0101 {
0102 typedef R type(std::tuple<decay_t<Args>...>);
0103 };
0104
0105 }
0106 }
0107
0108 #if !defined(GENERATING_DOCUMENTATION)
0109
0110 template <typename CompletionToken, typename Signature>
0111 struct async_result<experimental::as_single_t<CompletionToken>, Signature>
0112 {
0113 template <typename Initiation>
0114 struct init_wrapper
0115 {
0116 init_wrapper(Initiation init)
0117 : initiation_(static_cast<Initiation&&>(init))
0118 {
0119 }
0120
0121 template <typename Handler, typename... Args>
0122 void operator()(Handler&& handler, Args&&... args)
0123 {
0124 static_cast<Initiation&&>(initiation_)(
0125 experimental::detail::as_single_handler<decay_t<Handler>>(
0126 static_cast<Handler&&>(handler)),
0127 static_cast<Args&&>(args)...);
0128 }
0129
0130 Initiation initiation_;
0131 };
0132
0133 template <typename Initiation, typename RawCompletionToken, typename... Args>
0134 static auto initiate(Initiation&& initiation,
0135 RawCompletionToken&& token, Args&&... args)
0136 -> decltype(
0137 async_initiate<CompletionToken,
0138 typename experimental::detail::as_single_signature<Signature>::type>(
0139 init_wrapper<decay_t<Initiation>>(
0140 static_cast<Initiation&&>(initiation)),
0141 token.token_, static_cast<Args&&>(args)...))
0142 {
0143 return async_initiate<CompletionToken,
0144 typename experimental::detail::as_single_signature<Signature>::type>(
0145 init_wrapper<decay_t<Initiation>>(
0146 static_cast<Initiation&&>(initiation)),
0147 token.token_, static_cast<Args&&>(args)...);
0148 }
0149 };
0150
0151 template <template <typename, typename> class Associator,
0152 typename Handler, typename DefaultCandidate>
0153 struct associator<Associator,
0154 experimental::detail::as_single_handler<Handler>, DefaultCandidate>
0155 : Associator<Handler, DefaultCandidate>
0156 {
0157 static typename Associator<Handler, DefaultCandidate>::type get(
0158 const experimental::detail::as_single_handler<Handler>& h) noexcept
0159 {
0160 return Associator<Handler, DefaultCandidate>::get(h.handler_);
0161 }
0162
0163 static auto get(const experimental::detail::as_single_handler<Handler>& h,
0164 const DefaultCandidate& c) noexcept
0165 -> decltype(Associator<Handler, DefaultCandidate>::get(h.handler_, c))
0166 {
0167 return Associator<Handler, DefaultCandidate>::get(h.handler_, c);
0168 }
0169 };
0170
0171 #endif
0172
0173 }
0174 }
0175
0176 #include <boost/asio/detail/pop_options.hpp>
0177
0178 #endif