@@ -50,8 +50,14 @@ struct with_diag_handler_fn
50
50
std::shared_ptr<diagnostics> owning_diag;
51
51
};
52
52
53
+ // By default, don't modify the signature.
54
+ // This makes asio::as_tuple(with_diagnostics(X)) equivalent
55
+ // to asio::as_tuple(X).
53
56
template <typename Signature>
54
- struct with_diag_signature ;
57
+ struct with_diag_signature
58
+ {
59
+ using type = Signature;
60
+ };
55
61
56
62
template <typename R, typename ... Args>
57
63
struct with_diag_signature <R(error_code, Args...)>
@@ -146,14 +152,23 @@ struct with_diag_init : public Initiation
146
152
}
147
153
};
148
154
149
- } // namespace detail
150
- } // namespace mysql
155
+ // Did with_diagnostics modify any of the signatures?
156
+ // We really support only modifying all or none, and that's enough.
157
+ template <class Signature >
158
+ using with_diag_has_original_signature = std::
159
+ is_same<Signature, typename with_diag_signature<Signature>::type>;
151
160
152
- namespace asio {
161
+ template <class ... Signatures>
162
+ using with_diag_has_original_signatures = mp11::
163
+ mp_all_of<mp11::mp_list<Signatures...>, with_diag_has_original_signature>;
153
164
165
+ template <typename CompletionToken, bool has_original_signatures, typename ... Signatures>
166
+ struct with_diagnostics_async_result ;
167
+
168
+ // async_result when the signature was modified
154
169
template <typename CompletionToken, typename ... Signatures>
155
- struct async_result <mysql:: with_diagnostics_t < CompletionToken> , Signatures...>
156
- : async_result<CompletionToken, typename mysql::detail:: with_diag_signature<Signatures>::type...>
170
+ struct with_diagnostics_async_result < CompletionToken, false , Signatures...>
171
+ : asio:: async_result<CompletionToken, typename with_diag_signature<Signatures>::type...>
157
172
{
158
173
template <class RawCompletionToken >
159
174
using maybe_const_token_t = typename std::conditional<
@@ -163,26 +178,65 @@ struct async_result<mysql::with_diagnostics_t<CompletionToken>, Signatures...>
163
178
164
179
template <typename Initiation, typename RawCompletionToken, typename ... Args>
165
180
static auto initiate (Initiation&& initiation, RawCompletionToken&& token, Args&&... args)
166
- -> decltype(async_initiate<
181
+ -> decltype(asio:: async_initiate<
167
182
maybe_const_token_t <RawCompletionToken>,
168
- typename mysql::detail:: with_diag_signature<Signatures>::type...>(
169
- std::declval<mysql::detail:: with_diag_init<typename std::decay<Initiation>::type>>() ,
170
- mysql::detail:: access::get_impl(token),
183
+ typename with_diag_signature<Signatures>::type...>(
184
+ with_diag_init<typename std::decay<Initiation>::type>{std::forward<Initiation>(initiation)} ,
185
+ access::get_impl (token),
171
186
std::forward<Args>(args)...
172
187
))
173
188
{
174
- return async_initiate<
189
+ return asio:: async_initiate<
175
190
maybe_const_token_t <RawCompletionToken>,
176
- typename mysql::detail::with_diag_signature<Signatures>::type...>(
177
- mysql::detail::with_diag_init<typename std::decay<Initiation>::type>{
178
- std::forward<Initiation>(initiation)
179
- },
180
- mysql::detail::access::get_impl (token),
191
+ typename with_diag_signature<Signatures>::type...>(
192
+ with_diag_init<typename std::decay<Initiation>::type>{std::forward<Initiation>(initiation)},
193
+ access ::get_impl (token),
181
194
std::forward<Args>(args)...
182
195
);
183
196
}
184
197
};
185
198
199
+ // async_result when the signature wasn't modified (pass-through)
200
+ template <typename CompletionToken, typename ... Signatures>
201
+ struct with_diagnostics_async_result <CompletionToken, true , Signatures...>
202
+ : asio::async_result<CompletionToken, Signatures...>
203
+ {
204
+ template <class RawCompletionToken >
205
+ using maybe_const_token_t = typename std::conditional<
206
+ std::is_const<typename std::remove_reference<RawCompletionToken>::type>::value,
207
+ const CompletionToken,
208
+ CompletionToken>::type;
209
+
210
+ template <typename Initiation, typename RawCompletionToken, typename ... Args>
211
+ static auto initiate (Initiation&& initiation, RawCompletionToken&& token, Args&&... args)
212
+ -> decltype(asio::async_initiate<maybe_const_token_t <RawCompletionToken>, Signatures...>(
213
+ std::forward<Initiation>(initiation),
214
+ access::get_impl(token),
215
+ std::forward<Args>(args)...
216
+ ))
217
+ {
218
+ return asio::async_initiate<maybe_const_token_t <RawCompletionToken>, Signatures...>(
219
+ std::forward<Initiation>(initiation),
220
+ access ::get_impl (token),
221
+ std::forward<Args>(args)...
222
+ );
223
+ }
224
+ };
225
+
226
+ } // namespace detail
227
+ } // namespace mysql
228
+
229
+ namespace asio {
230
+
231
+ template <typename CompletionToken, typename ... Signatures>
232
+ struct async_result <mysql::with_diagnostics_t <CompletionToken>, Signatures...>
233
+ : mysql::detail::with_diagnostics_async_result<
234
+ CompletionToken,
235
+ mysql::detail::with_diag_has_original_signatures<Signatures...>::value,
236
+ Signatures...>
237
+ {
238
+ };
239
+
186
240
} // namespace asio
187
241
} // namespace boost
188
242
0 commit comments