Skip to content

Commit d0fb6bc

Browse files
committed
Fix the default handling of lvalue-qualified signatures in async_result.
1 parent 18be602 commit d0fb6bc

File tree

1 file changed

+66
-17
lines changed

1 file changed

+66
-17
lines changed

asio/include/asio/async_result.hpp

Lines changed: 66 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -97,39 +97,39 @@ struct is_completion_handler_for : false_type
9797

9898
template <typename T, typename R, typename... Args>
9999
struct is_completion_handler_for<T, R(Args...)>
100-
: integral_constant<bool, (callable_with<T, Args...>)>
100+
: integral_constant<bool, (callable_with<decay_t<T>, Args...>)>
101101
{
102102
};
103103

104104
template <typename T, typename R, typename... Args>
105105
struct is_completion_handler_for<T, R(Args...) &>
106-
: integral_constant<bool, (callable_with<T&, Args...>)>
106+
: integral_constant<bool, (callable_with<decay_t<T>&, Args...>)>
107107
{
108108
};
109109

110110
template <typename T, typename R, typename... Args>
111111
struct is_completion_handler_for<T, R(Args...) &&>
112-
: integral_constant<bool, (callable_with<T&&, Args...>)>
112+
: integral_constant<bool, (callable_with<decay_t<T>&&, Args...>)>
113113
{
114114
};
115115

116116
# if defined(ASIO_HAS_NOEXCEPT_FUNCTION_TYPE)
117117

118118
template <typename T, typename R, typename... Args>
119119
struct is_completion_handler_for<T, R(Args...) noexcept>
120-
: integral_constant<bool, (callable_with<T, Args...>)>
120+
: integral_constant<bool, (callable_with<decay_t<T>, Args...>)>
121121
{
122122
};
123123

124124
template <typename T, typename R, typename... Args>
125125
struct is_completion_handler_for<T, R(Args...) & noexcept>
126-
: integral_constant<bool, (callable_with<T&, Args...>)>
126+
: integral_constant<bool, (callable_with<decay_t<T>&, Args...>)>
127127
{
128128
};
129129

130130
template <typename T, typename R, typename... Args>
131131
struct is_completion_handler_for<T, R(Args...) && noexcept>
132-
: integral_constant<bool, (callable_with<T&&, Args...>)>
132+
: integral_constant<bool, (callable_with<decay_t<T>&&, Args...>)>
133133
{
134134
};
135135

@@ -176,37 +176,84 @@ ASIO_CONCEPT completion_handler_for =
176176
namespace detail {
177177

178178
template <typename T>
179-
struct is_simple_completion_signature : false_type
179+
struct is_lvalue_completion_signature : false_type
180+
{
181+
};
182+
183+
template <typename R, typename... Args>
184+
struct is_lvalue_completion_signature<R(Args...) &> : true_type
185+
{
186+
};
187+
188+
# if defined(ASIO_HAS_NOEXCEPT_FUNCTION_TYPE)
189+
190+
template <typename R, typename... Args>
191+
struct is_lvalue_completion_signature<R(Args...) & noexcept> : true_type
192+
{
193+
};
194+
195+
# endif // defined(ASIO_HAS_NOEXCEPT_FUNCTION_TYPE)
196+
197+
template <typename... Signatures>
198+
struct are_any_lvalue_completion_signatures : false_type
199+
{
200+
};
201+
202+
template <typename Sig0>
203+
struct are_any_lvalue_completion_signatures<Sig0>
204+
: is_lvalue_completion_signature<Sig0>
205+
{
206+
};
207+
208+
template <typename Sig0, typename... SigN>
209+
struct are_any_lvalue_completion_signatures<Sig0, SigN...>
210+
: integral_constant<bool, (
211+
is_lvalue_completion_signature<Sig0>::value
212+
|| are_any_lvalue_completion_signatures<SigN...>::value)>
180213
{
181214
};
182215

183216
template <typename T>
184-
struct simple_completion_signature;
217+
struct is_rvalue_completion_signature : false_type
218+
{
219+
};
185220

186221
template <typename R, typename... Args>
187-
struct is_simple_completion_signature<R(Args...)> : true_type
222+
struct is_rvalue_completion_signature<R(Args...) &&> : true_type
188223
{
189224
};
190225

226+
# if defined(ASIO_HAS_NOEXCEPT_FUNCTION_TYPE)
227+
228+
template <typename R, typename... Args>
229+
struct is_rvalue_completion_signature<R(Args...) && noexcept> : true_type
230+
{
231+
};
232+
233+
# endif // defined(ASIO_HAS_NOEXCEPT_FUNCTION_TYPE)
234+
191235
template <typename... Signatures>
192-
struct are_simple_completion_signatures : false_type
236+
struct are_any_rvalue_completion_signatures : false_type
193237
{
194238
};
195239

196240
template <typename Sig0>
197-
struct are_simple_completion_signatures<Sig0>
198-
: is_simple_completion_signature<Sig0>
241+
struct are_any_rvalue_completion_signatures<Sig0>
242+
: is_rvalue_completion_signature<Sig0>
199243
{
200244
};
201245

202246
template <typename Sig0, typename... SigN>
203-
struct are_simple_completion_signatures<Sig0, SigN...>
247+
struct are_any_rvalue_completion_signatures<Sig0, SigN...>
204248
: integral_constant<bool, (
205-
is_simple_completion_signature<Sig0>::value
206-
&& are_simple_completion_signatures<SigN...>::value)>
249+
is_rvalue_completion_signature<Sig0>::value
250+
|| are_any_rvalue_completion_signatures<SigN...>::value)>
207251
{
208252
};
209253

254+
template <typename T>
255+
struct simple_completion_signature;
256+
210257
template <typename R, typename... Args>
211258
struct simple_completion_signature<R(Args...)>
212259
{
@@ -344,15 +391,17 @@ template <typename CompletionToken,
344391
ASIO_COMPLETION_SIGNATURE... Signatures>
345392
class async_result :
346393
public conditional_t<
347-
detail::are_simple_completion_signatures<Signatures...>::value,
394+
detail::are_any_lvalue_completion_signatures<Signatures...>::value
395+
|| !detail::are_any_rvalue_completion_signatures<Signatures...>::value,
348396
detail::completion_handler_async_result<CompletionToken, Signatures...>,
349397
async_result<CompletionToken,
350398
typename detail::simple_completion_signature<Signatures>::type...>
351399
>
352400
{
353401
public:
354402
typedef conditional_t<
355-
detail::are_simple_completion_signatures<Signatures...>::value,
403+
detail::are_any_lvalue_completion_signatures<Signatures...>::value
404+
|| !detail::are_any_rvalue_completion_signatures<Signatures...>::value,
356405
detail::completion_handler_async_result<CompletionToken, Signatures...>,
357406
async_result<CompletionToken,
358407
typename detail::simple_completion_signature<Signatures>::type...>

0 commit comments

Comments
 (0)