]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/boost/asio/experimental/impl/as_single.hpp
update ceph source to reef 18.1.2
[ceph.git] / ceph / src / boost / boost / asio / experimental / impl / as_single.hpp
1 //
2 // experimental/impl/as_single.hpp
3 // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
4 //
5 // Copyright (c) 2003-2022 Christopher M. Kohlhoff (chris at kohlhoff dot com)
6 //
7 // Distributed under the Boost Software License, Version 1.0. (See accompanying
8 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
9 //
10
11 #ifndef BOOST_ASIO_IMPL_EXPERIMENTAL_AS_SINGLE_HPP
12 #define BOOST_ASIO_IMPL_EXPERIMENTAL_AS_SINGLE_HPP
13
14 #if defined(_MSC_VER) && (_MSC_VER >= 1200)
15 # pragma once
16 #endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
17
18 #include <boost/asio/detail/config.hpp>
19
20 #include <tuple>
21
22 #include <boost/asio/associator.hpp>
23 #include <boost/asio/async_result.hpp>
24 #include <boost/asio/detail/handler_alloc_helpers.hpp>
25 #include <boost/asio/detail/handler_cont_helpers.hpp>
26 #include <boost/asio/detail/handler_invoke_helpers.hpp>
27 #include <boost/asio/detail/type_traits.hpp>
28 #include <boost/asio/detail/variadic_templates.hpp>
29
30 #include <boost/asio/detail/push_options.hpp>
31
32 namespace boost {
33 namespace asio {
34 namespace experimental {
35 namespace detail {
36
37 // Class to adapt a as_single_t as a completion handler.
38 template <typename Handler>
39 class as_single_handler
40 {
41 public:
42 typedef void result_type;
43
44 template <typename CompletionToken>
45 as_single_handler(as_single_t<CompletionToken> e)
46 : handler_(BOOST_ASIO_MOVE_CAST(CompletionToken)(e.token_))
47 {
48 }
49
50 template <typename RedirectedHandler>
51 as_single_handler(BOOST_ASIO_MOVE_ARG(RedirectedHandler) h)
52 : handler_(BOOST_ASIO_MOVE_CAST(RedirectedHandler)(h))
53 {
54 }
55
56 void operator()()
57 {
58 BOOST_ASIO_MOVE_OR_LVALUE(Handler)(handler_)();
59 }
60
61 template <typename Arg>
62 void operator()(BOOST_ASIO_MOVE_ARG(Arg) arg)
63 {
64 BOOST_ASIO_MOVE_OR_LVALUE(Handler)(handler_)(
65 BOOST_ASIO_MOVE_CAST(Arg)(arg));
66 }
67
68 template <typename... Args>
69 void operator()(BOOST_ASIO_MOVE_ARG(Args)... args)
70 {
71 BOOST_ASIO_MOVE_OR_LVALUE(Handler)(handler_)(
72 std::make_tuple(BOOST_ASIO_MOVE_CAST(Args)(args)...));
73 }
74
75 //private:
76 Handler handler_;
77 };
78
79 template <typename Handler>
80 inline asio_handler_allocate_is_deprecated
81 asio_handler_allocate(std::size_t size,
82 as_single_handler<Handler>* this_handler)
83 {
84 #if defined(BOOST_ASIO_NO_DEPRECATED)
85 boost_asio_handler_alloc_helpers::allocate(size, this_handler->handler_);
86 return asio_handler_allocate_is_no_longer_used();
87 #else // defined(BOOST_ASIO_NO_DEPRECATED)
88 return boost_asio_handler_alloc_helpers::allocate(
89 size, this_handler->handler_);
90 #endif // defined(BOOST_ASIO_NO_DEPRECATED)
91 }
92
93 template <typename Handler>
94 inline asio_handler_deallocate_is_deprecated
95 asio_handler_deallocate(void* pointer, std::size_t size,
96 as_single_handler<Handler>* this_handler)
97 {
98 boost_asio_handler_alloc_helpers::deallocate(
99 pointer, size, this_handler->handler_);
100 #if defined(BOOST_ASIO_NO_DEPRECATED)
101 return asio_handler_deallocate_is_no_longer_used();
102 #endif // defined(BOOST_ASIO_NO_DEPRECATED)
103 }
104
105 template <typename Handler>
106 inline bool asio_handler_is_continuation(
107 as_single_handler<Handler>* this_handler)
108 {
109 return boost_asio_handler_cont_helpers::is_continuation(
110 this_handler->handler_);
111 }
112
113 template <typename Function, typename Handler>
114 inline asio_handler_invoke_is_deprecated
115 asio_handler_invoke(Function& function,
116 as_single_handler<Handler>* this_handler)
117 {
118 boost_asio_handler_invoke_helpers::invoke(
119 function, this_handler->handler_);
120 #if defined(BOOST_ASIO_NO_DEPRECATED)
121 return asio_handler_invoke_is_no_longer_used();
122 #endif // defined(BOOST_ASIO_NO_DEPRECATED)
123 }
124
125 template <typename Function, typename Handler>
126 inline asio_handler_invoke_is_deprecated
127 asio_handler_invoke(const Function& function,
128 as_single_handler<Handler>* this_handler)
129 {
130 boost_asio_handler_invoke_helpers::invoke(
131 function, this_handler->handler_);
132 #if defined(BOOST_ASIO_NO_DEPRECATED)
133 return asio_handler_invoke_is_no_longer_used();
134 #endif // defined(BOOST_ASIO_NO_DEPRECATED)
135 }
136
137 template <typename Signature>
138 struct as_single_signature
139 {
140 typedef Signature type;
141 };
142
143 template <typename R>
144 struct as_single_signature<R()>
145 {
146 typedef R type();
147 };
148
149 template <typename R, typename Arg>
150 struct as_single_signature<R(Arg)>
151 {
152 typedef R type(Arg);
153 };
154
155 template <typename R, typename... Args>
156 struct as_single_signature<R(Args...)>
157 {
158 typedef R type(std::tuple<typename decay<Args>::type...>);
159 };
160
161 } // namespace detail
162 } // namespace experimental
163
164 #if !defined(GENERATING_DOCUMENTATION)
165
166 template <typename CompletionToken, typename Signature>
167 struct async_result<experimental::as_single_t<CompletionToken>, Signature>
168 {
169 typedef typename async_result<CompletionToken,
170 typename experimental::detail::as_single_signature<Signature>::type>
171 ::return_type return_type;
172
173 template <typename Initiation>
174 struct init_wrapper
175 {
176 init_wrapper(Initiation init)
177 : initiation_(BOOST_ASIO_MOVE_CAST(Initiation)(init))
178 {
179 }
180
181 template <typename Handler, typename... Args>
182 void operator()(
183 BOOST_ASIO_MOVE_ARG(Handler) handler,
184 BOOST_ASIO_MOVE_ARG(Args)... args)
185 {
186 BOOST_ASIO_MOVE_CAST(Initiation)(initiation_)(
187 experimental::detail::as_single_handler<
188 typename decay<Handler>::type>(
189 BOOST_ASIO_MOVE_CAST(Handler)(handler)),
190 BOOST_ASIO_MOVE_CAST(Args)(args)...);
191 }
192
193 Initiation initiation_;
194 };
195
196 template <typename Initiation, typename RawCompletionToken, typename... Args>
197 static return_type initiate(
198 BOOST_ASIO_MOVE_ARG(Initiation) initiation,
199 BOOST_ASIO_MOVE_ARG(RawCompletionToken) token,
200 BOOST_ASIO_MOVE_ARG(Args)... args)
201 {
202 return async_initiate<CompletionToken,
203 typename experimental::detail::as_single_signature<Signature>::type>(
204 init_wrapper<typename decay<Initiation>::type>(
205 BOOST_ASIO_MOVE_CAST(Initiation)(initiation)),
206 token.token_, BOOST_ASIO_MOVE_CAST(Args)(args)...);
207 }
208 };
209
210 template <template <typename, typename> class Associator,
211 typename Handler, typename DefaultCandidate>
212 struct associator<Associator,
213 experimental::detail::as_single_handler<Handler>, DefaultCandidate>
214 : Associator<Handler, DefaultCandidate>
215 {
216 static typename Associator<Handler, DefaultCandidate>::type get(
217 const experimental::detail::as_single_handler<Handler>& h,
218 const DefaultCandidate& c = DefaultCandidate()) BOOST_ASIO_NOEXCEPT
219 {
220 return Associator<Handler, DefaultCandidate>::get(h.handler_, c);
221 }
222 };
223
224 #endif // !defined(GENERATING_DOCUMENTATION)
225
226 } // namespace asio
227 } // namespace boost
228
229 #include <boost/asio/detail/pop_options.hpp>
230
231 #endif // BOOST_ASIO_IMPL_EXPERIMENTAL_AS_SINGLE_HPP