]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/boost/asio/async_result.hpp
update sources to v12.2.3
[ceph.git] / ceph / src / boost / boost / asio / async_result.hpp
1 //
2 // async_result.hpp
3 // ~~~~~~~~~~~~~~~~
4 //
5 // Copyright (c) 2003-2017 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_ASYNC_RESULT_HPP
12 #define BOOST_ASIO_ASYNC_RESULT_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 #include <boost/asio/detail/type_traits.hpp>
20 #include <boost/asio/handler_type.hpp>
21
22 #include <boost/asio/detail/push_options.hpp>
23
24 namespace boost {
25 namespace asio {
26
27 /// An interface for customising the behaviour of an initiating function.
28 /**
29 * The async_result traits class is used for determining:
30 *
31 * @li the concrete completion handler type to be called at the end of the
32 * asynchronous operation;
33 *
34 * @li the initiating function return type; and
35 *
36 * @li how the return value of the initiating function is obtained.
37 *
38 * The trait allows the handler and return types to be determined at the point
39 * where the specific completion handler signature is known.
40 *
41 * This template may be specialised for user-defined completion token types.
42 * The primary template assumes that the CompletionToken is the completion
43 * handler.
44 */
45 #if defined(BOOST_ASIO_NO_DEPRECATED) || defined(GENERATING_DOCUMENTATION)
46 template <typename CompletionToken, typename Signature>
47 #else // defined(BOOST_ASIO_NO_DEPRECATED) || defined(GENERATING_DOCUMENTATION)
48 template <typename CompletionToken, typename Signature = void>
49 #endif // defined(BOOST_ASIO_NO_DEPRECATED) || defined(GENERATING_DOCUMENTATION)
50 class async_result
51 {
52 public:
53 #if defined(BOOST_ASIO_NO_DEPRECATED) || defined(GENERATING_DOCUMENTATION)
54 /// The concrete completion handler type for the specific signature.
55 typedef CompletionToken completion_handler_type;
56
57 /// The return type of the initiating function.
58 typedef void return_type;
59 #else // defined(BOOST_ASIO_NO_DEPRECATED) || defined(GENERATING_DOCUMENTATION)
60 // For backward compatibility, determine the concrete completion handler type
61 // by using the legacy handler_type trait.
62 typedef typename handler_type<CompletionToken, Signature>::type
63 completion_handler_type;
64
65 // For backward compatibility, determine the initiating function return type
66 // using the legacy single-parameter version of async_result.
67 typedef typename async_result<completion_handler_type>::type return_type;
68 #endif // defined(BOOST_ASIO_NO_DEPRECATED) || defined(GENERATING_DOCUMENTATION)
69
70 /// Construct an async result from a given handler.
71 /**
72 * When using a specalised async_result, the constructor has an opportunity
73 * to initialise some state associated with the completion handler, which is
74 * then returned from the initiating function.
75 */
76 explicit async_result(completion_handler_type& h)
77 #if defined(BOOST_ASIO_NO_DEPRECATED) || defined(GENERATING_DOCUMENTATION)
78 // No data members to initialise.
79 #else // defined(BOOST_ASIO_NO_DEPRECATED) || defined(GENERATING_DOCUMENTATION)
80 : legacy_result_(h)
81 #endif // defined(BOOST_ASIO_NO_DEPRECATED) || defined(GENERATING_DOCUMENTATION)
82 {
83 (void)h;
84 }
85
86 /// Obtain the value to be returned from the initiating function.
87 return_type get()
88 {
89 #if defined(BOOST_ASIO_NO_DEPRECATED) || defined(GENERATING_DOCUMENTATION)
90 // Nothing to do.
91 #else // defined(BOOST_ASIO_NO_DEPRECATED) || defined(GENERATING_DOCUMENTATION)
92 return legacy_result_.get();
93 #endif // defined(BOOST_ASIO_NO_DEPRECATED) || defined(GENERATING_DOCUMENTATION)
94 }
95
96 private:
97 async_result(const async_result&) BOOST_ASIO_DELETED;
98 async_result& operator=(const async_result&) BOOST_ASIO_DELETED;
99
100 #if defined(BOOST_ASIO_NO_DEPRECATED) || defined(GENERATING_DOCUMENTATION)
101 // No data members.
102 #else // defined(BOOST_ASIO_NO_DEPRECATED) || defined(GENERATING_DOCUMENTATION)
103 async_result<completion_handler_type> legacy_result_;
104 #endif // defined(BOOST_ASIO_NO_DEPRECATED) || defined(GENERATING_DOCUMENTATION)
105 };
106
107 #if !defined(BOOST_ASIO_NO_DEPRECATED)
108
109 /// (Deprecated: Use two-parameter version of async_result.) An interface for
110 /// customising the behaviour of an initiating function.
111 /**
112 * This template may be specialised for user-defined handler types.
113 */
114 template <typename Handler>
115 class async_result<Handler>
116 {
117 public:
118 /// The return type of the initiating function.
119 typedef void type;
120
121 /// Construct an async result from a given handler.
122 /**
123 * When using a specalised async_result, the constructor has an opportunity
124 * to initialise some state associated with the handler, which is then
125 * returned from the initiating function.
126 */
127 explicit async_result(Handler&)
128 {
129 }
130
131 /// Obtain the value to be returned from the initiating function.
132 type get()
133 {
134 }
135 };
136
137 #endif // !defined(BOOST_ASIO_NO_DEPRECATED)
138
139 /// Helper template to deduce the handler type from a CompletionToken, capture
140 /// a local copy of the handler, and then create an async_result for the
141 /// handler.
142 template <typename CompletionToken, typename Signature>
143 struct async_completion
144 {
145 /// The real handler type to be used for the asynchronous operation.
146 typedef typename boost::asio::async_result<
147 typename decay<CompletionToken>::type,
148 Signature>::completion_handler_type completion_handler_type;
149
150 #if defined(BOOST_ASIO_HAS_MOVE) || defined(GENERATING_DOCUMENTATION)
151 /// Constructor.
152 /**
153 * The constructor creates the concrete completion handler and makes the link
154 * between the handler and the asynchronous result.
155 */
156 explicit async_completion(CompletionToken& token)
157 : completion_handler(static_cast<typename conditional<
158 is_same<CompletionToken, completion_handler_type>::value,
159 completion_handler_type&, CompletionToken&&>::type>(token)),
160 result(completion_handler)
161 {
162 }
163 #else // defined(BOOST_ASIO_HAS_MOVE) || defined(GENERATING_DOCUMENTATION)
164 explicit async_completion(typename decay<CompletionToken>::type& token)
165 : completion_handler(token),
166 result(completion_handler)
167 {
168 }
169
170 explicit async_completion(const typename decay<CompletionToken>::type& token)
171 : completion_handler(token),
172 result(completion_handler)
173 {
174 }
175 #endif // defined(BOOST_ASIO_HAS_MOVE) || defined(GENERATING_DOCUMENTATION)
176
177 /// A copy of, or reference to, a real handler object.
178 #if defined(BOOST_ASIO_HAS_MOVE) || defined(GENERATING_DOCUMENTATION)
179 typename conditional<
180 is_same<CompletionToken, completion_handler_type>::value,
181 completion_handler_type&, completion_handler_type>::type completion_handler;
182 #else // defined(BOOST_ASIO_HAS_MOVE) || defined(GENERATING_DOCUMENTATION)
183 completion_handler_type completion_handler;
184 #endif // defined(BOOST_ASIO_HAS_MOVE) || defined(GENERATING_DOCUMENTATION)
185
186 /// The result of the asynchronous operation's initiating function.
187 async_result<typename decay<CompletionToken>::type, Signature> result;
188 };
189
190 namespace detail {
191
192 template <typename CompletionToken, typename Signature>
193 struct async_result_helper
194 : async_result<typename decay<CompletionToken>::type, Signature>
195 {
196 };
197
198 } // namespace detail
199 } // namespace asio
200 } // namespace boost
201
202 #include <boost/asio/detail/pop_options.hpp>
203
204 #if defined(GENERATING_DOCUMENTATION)
205 # define BOOST_ASIO_INITFN_RESULT_TYPE(ct, sig) \
206 void_or_deduced
207 #elif defined(_MSC_VER) && (_MSC_VER < 1500)
208 # define BOOST_ASIO_INITFN_RESULT_TYPE(ct, sig) \
209 typename ::boost::asio::detail::async_result_helper< \
210 ct, sig>::return_type
211 #define BOOST_ASIO_HANDLER_TYPE(ct, sig) \
212 typename ::boost::asio::detail::async_result_helper< \
213 ct, sig>::completion_handler_type
214 #else
215 # define BOOST_ASIO_INITFN_RESULT_TYPE(ct, sig) \
216 typename ::boost::asio::async_result< \
217 typename ::boost::asio::decay<ct>::type, sig>::return_type
218 #define BOOST_ASIO_HANDLER_TYPE(ct, sig) \
219 typename ::boost::asio::async_result< \
220 typename ::boost::asio::decay<ct>::type, sig>::completion_handler_type
221 #endif
222
223 #endif // BOOST_ASIO_ASYNC_RESULT_HPP