execute.hpp
6.96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
//
// execution/execute.hpp
// ~~~~~~~~~~~~~~~~~~~~~
//
// Copyright (c) 2003-2020 Christopher M. Kohlhoff (chris at kohlhoff dot com)
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//
#ifndef ASIO_EXECUTION_EXECUTE_HPP
#define ASIO_EXECUTION_EXECUTE_HPP
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
# pragma once
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
#include "asio/detail/config.hpp"
#include "asio/detail/type_traits.hpp"
#include "asio/execution/detail/as_invocable.hpp"
#include "asio/execution/detail/as_receiver.hpp"
#include "asio/traits/execute_member.hpp"
#include "asio/traits/execute_free.hpp"
#include "asio/detail/push_options.hpp"
#if defined(GENERATING_DOCUMENTATION)
namespace asio {
namespace execution {
/// A customisation point that executes a function on an executor.
/**
* The name <tt>execution::execute</tt> denotes a customisation point object.
*
* For some subexpressions <tt>e</tt> and <tt>f</tt>, let <tt>E</tt> be a type
* such that <tt>decltype((e))</tt> is <tt>E</tt> and let <tt>F</tt> be a type
* such that <tt>decltype((f))</tt> is <tt>F</tt>. The expression
* <tt>execution::execute(e, f)</tt> is ill-formed if <tt>F</tt> does not model
* <tt>invocable</tt>, or if <tt>E</tt> does not model either <tt>executor</tt>
* or <tt>sender</tt>. Otherwise, it is expression-equivalent to:
*
* @li <tt>e.execute(f)</tt>, if that expression is valid. If the function
* selected does not execute the function object <tt>f</tt> on the executor
* <tt>e</tt>, the program is ill-formed with no diagnostic required.
*
* @li Otherwise, <tt>execute(e, f)</tt>, if that expression is valid, with
* overload resolution performed in a context that includes the declaration
* <tt>void execute();</tt> and that does not include a declaration of
* <tt>execution::execute</tt>. If the function selected by overload
* resolution does not execute the function object <tt>f</tt> on the executor
* <tt>e</tt>, the program is ill-formed with no diagnostic required.
*/
inline constexpr unspecified execute = unspecified;
/// A type trait that determines whether a @c execute expression is well-formed.
/**
* Class template @c can_execute is a trait that is derived from
* @c true_type if the expression <tt>execution::execute(std::declval<T>(),
* std::declval<F>())</tt> is well formed; otherwise @c false_type.
*/
template <typename T, typename F>
struct can_execute :
integral_constant<bool, automatically_determined>
{
};
} // namespace execution
} // namespace asio
#else // defined(GENERATING_DOCUMENTATION)
namespace asio {
namespace execution {
template <typename T, typename R>
struct is_sender_to;
namespace detail {
template <typename S, typename R>
void submit_helper(ASIO_MOVE_ARG(S) s, ASIO_MOVE_ARG(R) r);
} // namespace detail
} // namespace execution
} // namespace asio
namespace asio_execution_execute_fn {
using asio::conditional;
using asio::decay;
using asio::declval;
using asio::enable_if;
using asio::execution::detail::as_receiver;
using asio::execution::detail::is_as_invocable;
using asio::execution::is_sender_to;
using asio::false_type;
using asio::result_of;
using asio::traits::execute_free;
using asio::traits::execute_member;
using asio::true_type;
void execute();
enum overload_type
{
call_member,
call_free,
adapter,
ill_formed
};
template <typename T, typename F, typename = void>
struct call_traits
{
ASIO_STATIC_CONSTEXPR(overload_type, overload = ill_formed);
};
template <typename T, typename F>
struct call_traits<T, void(F),
typename enable_if<
(
execute_member<T, F>::is_valid
)
>::type> :
execute_member<T, F>
{
ASIO_STATIC_CONSTEXPR(overload_type, overload = call_member);
};
template <typename T, typename F>
struct call_traits<T, void(F),
typename enable_if<
(
!execute_member<T, F>::is_valid
&&
execute_free<T, F>::is_valid
)
>::type> :
execute_free<T, F>
{
ASIO_STATIC_CONSTEXPR(overload_type, overload = call_free);
};
template <typename T, typename F>
struct call_traits<T, void(F),
typename enable_if<
(
!execute_member<T, F>::is_valid
&&
!execute_free<T, F>::is_valid
&&
conditional<true, true_type,
typename result_of<typename decay<F>::type&()>::type
>::type::value
&&
conditional<
!is_as_invocable<
typename decay<F>::type
>::value,
is_sender_to<
T,
as_receiver<typename decay<F>::type, T>
>,
false_type
>::type::value
)
>::type>
{
ASIO_STATIC_CONSTEXPR(overload_type, overload = adapter);
ASIO_STATIC_CONSTEXPR(bool, is_valid = true);
ASIO_STATIC_CONSTEXPR(bool, is_noexcept = false);
typedef void result_type;
};
struct impl
{
template <typename T, typename F>
ASIO_CONSTEXPR typename enable_if<
call_traits<T, void(F)>::overload == call_member,
typename call_traits<T, void(F)>::result_type
>::type
operator()(
ASIO_MOVE_ARG(T) t,
ASIO_MOVE_ARG(F) f) const
ASIO_NOEXCEPT_IF((
call_traits<T, void(F)>::is_noexcept))
{
return ASIO_MOVE_CAST(T)(t).execute(ASIO_MOVE_CAST(F)(f));
}
template <typename T, typename F>
ASIO_CONSTEXPR typename enable_if<
call_traits<T, void(F)>::overload == call_free,
typename call_traits<T, void(F)>::result_type
>::type
operator()(
ASIO_MOVE_ARG(T) t,
ASIO_MOVE_ARG(F) f) const
ASIO_NOEXCEPT_IF((
call_traits<T, void(F)>::is_noexcept))
{
return execute(ASIO_MOVE_CAST(T)(t), ASIO_MOVE_CAST(F)(f));
}
template <typename T, typename F>
ASIO_CONSTEXPR typename enable_if<
call_traits<T, void(F)>::overload == adapter,
typename call_traits<T, void(F)>::result_type
>::type
operator()(
ASIO_MOVE_ARG(T) t,
ASIO_MOVE_ARG(F) f) const
ASIO_NOEXCEPT_IF((
call_traits<T, void(F)>::is_noexcept))
{
return asio::execution::detail::submit_helper(
ASIO_MOVE_CAST(T)(t),
as_receiver<typename decay<F>::type, T>(
ASIO_MOVE_CAST(F)(f), 0));
}
};
template <typename T = impl>
struct static_instance
{
static const T instance;
};
template <typename T>
const T static_instance<T>::instance = {};
} // namespace asio_execution_execute_fn
namespace asio {
namespace execution {
namespace {
static ASIO_CONSTEXPR const asio_execution_execute_fn::impl&
execute = asio_execution_execute_fn::static_instance<>::instance;
} // namespace
template <typename T, typename F>
struct can_execute :
integral_constant<bool,
asio_execution_execute_fn::call_traits<T, void(F)>::overload !=
asio_execution_execute_fn::ill_formed>
{
};
#if defined(ASIO_HAS_VARIABLE_TEMPLATES)
template <typename T, typename F>
constexpr bool can_execute_v = can_execute<T, F>::value;
#endif // defined(ASIO_HAS_VARIABLE_TEMPLATES)
} // namespace execution
} // namespace asio
#endif // defined(GENERATING_DOCUMENTATION)
#include "asio/detail/pop_options.hpp"
#endif // ASIO_EXECUTION_EXECUTE_HPP