sender.hpp
7.95 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
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
//
// execution/sender.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_SENDER_HPP
#define ASIO_EXECUTION_SENDER_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/void_receiver.hpp"
#include "asio/execution/executor.hpp"
#include "asio/execution/receiver.hpp"
#include "asio/detail/push_options.hpp"
#if defined(ASIO_HAS_ALIAS_TEMPLATES) \
&& defined(ASIO_HAS_VARIADIC_TEMPLATES) \
&& defined(ASIO_HAS_DECLTYPE) \
&& !defined(ASIO_MSVC) || (_MSC_VER >= 1910)
# define ASIO_HAS_DEDUCED_EXECUTION_IS_TYPED_SENDER_TRAIT 1
#endif // defined(ASIO_HAS_ALIAS_TEMPLATES)
// && defined(ASIO_HAS_VARIADIC_TEMPLATES)
// && defined(ASIO_HAS_DECLTYPE)
// && !defined(ASIO_MSVC) || (_MSC_VER >= 1910)
namespace asio {
namespace execution {
namespace detail {
namespace sender_base_ns { struct sender_base {}; }
template <typename S, typename = void>
struct sender_traits_base
{
typedef void asio_execution_sender_traits_base_is_unspecialised;
};
template <typename S>
struct sender_traits_base<S,
typename enable_if<
is_base_of<sender_base_ns::sender_base, S>::value
>::type>
{
};
template <typename S, typename = void, typename = void, typename = void>
struct has_sender_types : false_type
{
};
#if defined(ASIO_HAS_DEDUCED_EXECUTION_IS_TYPED_SENDER_TRAIT)
template <
template <
template <typename...> class Tuple,
template <typename...> class Variant
> class>
struct has_value_types
{
typedef void type;
};
template <
template <
template <typename...> class Variant
> class>
struct has_error_types
{
typedef void type;
};
template <typename S>
struct has_sender_types<S,
typename has_value_types<S::template value_types>::type,
typename has_error_types<S::template error_types>::type,
typename conditional<S::sends_done, void, void>::type> : true_type
{
};
template <typename S>
struct sender_traits_base<S,
typename enable_if<
has_sender_types<S>::value
>::type>
{
template <
template <typename...> class Tuple,
template <typename...> class Variant>
using value_types = typename S::template value_types<Tuple, Variant>;
template <template <typename...> class Variant>
using error_types = typename S::template error_types<Variant>;
ASIO_STATIC_CONSTEXPR(bool, sends_done = S::sends_done);
};
#endif // defined(ASIO_HAS_DEDUCED_EXECUTION_IS_TYPED_SENDER_TRAIT)
template <typename S>
struct sender_traits_base<S,
typename enable_if<
!has_sender_types<S>::value
&& detail::is_executor_of_impl<S,
as_invocable<void_receiver, S> >::value
>::type>
{
#if defined(ASIO_HAS_DEDUCED_EXECUTION_IS_TYPED_SENDER_TRAIT) \
&& defined(ASIO_HAS_STD_EXCEPTION_PTR)
template <
template <typename...> class Tuple,
template <typename...> class Variant>
using value_types = Variant<Tuple<>>;
template <template <typename...> class Variant>
using error_types = Variant<std::exception_ptr>;
ASIO_STATIC_CONSTEXPR(bool, sends_done = true);
#endif // defined(ASIO_HAS_DEDUCED_EXECUTION_IS_TYPED_SENDER_TRAIT)
// && defined(ASIO_HAS_STD_EXCEPTION_PTR)
};
} // namespace detail
/// Base class used for tagging senders.
#if defined(GENERATING_DOCUMENTATION)
typedef unspecified sender_base;
#else // defined(GENERATING_DOCUMENTATION)
typedef detail::sender_base_ns::sender_base sender_base;
#endif // defined(GENERATING_DOCUMENTATION)
/// Traits for senders.
template <typename S>
struct sender_traits
#if !defined(GENERATING_DOCUMENTATION)
: detail::sender_traits_base<S>
#endif // !defined(GENERATING_DOCUMENTATION)
{
};
namespace detail {
template <typename S, typename = void>
struct has_sender_traits : true_type
{
};
template <typename S>
struct has_sender_traits<S,
typename enable_if<
is_same<
typename asio::execution::sender_traits<
S>::asio_execution_sender_traits_base_is_unspecialised,
void
>::value
>::type> : false_type
{
};
} // namespace detail
/// The is_sender trait detects whether a type T satisfies the
/// execution::sender concept.
/**
* Class template @c is_sender is a type trait that is derived from @c
* true_type if the type @c T meets the concept definition for a sender,
* otherwise @c false_type.
*/
template <typename T>
struct is_sender :
#if defined(GENERATING_DOCUMENTATION)
integral_constant<bool, automatically_determined>
#else // defined(GENERATING_DOCUMENTATION)
conditional<
detail::has_sender_traits<typename remove_cvref<T>::type>::value,
is_move_constructible<typename remove_cvref<T>::type>,
false_type
>::type
#endif // defined(GENERATING_DOCUMENTATION)
{
};
#if defined(ASIO_HAS_VARIABLE_TEMPLATES)
template <typename T>
ASIO_CONSTEXPR const bool is_sender_v = is_sender<T>::value;
#endif // defined(ASIO_HAS_VARIABLE_TEMPLATES)
#if defined(ASIO_HAS_CONCEPTS)
template <typename T>
ASIO_CONCEPT sender = is_sender<T>::value;
#define ASIO_EXECUTION_SENDER ::asio::execution::sender
#else // defined(ASIO_HAS_CONCEPTS)
#define ASIO_EXECUTION_SENDER typename
#endif // defined(ASIO_HAS_CONCEPTS)
template <typename S, typename R>
struct can_connect;
/// The is_sender_to trait detects whether a type T satisfies the
/// execution::sender_to concept for some receiver.
/**
* Class template @c is_sender_to is a type trait that is derived from @c
* true_type if the type @c T meets the concept definition for a sender
* for some receiver type R, otherwise @c false.
*/
template <typename T, typename R>
struct is_sender_to :
#if defined(GENERATING_DOCUMENTATION)
integral_constant<bool, automatically_determined>
#else // defined(GENERATING_DOCUMENTATION)
integral_constant<bool,
is_sender<T>::value
&& is_receiver<R>::value
&& can_connect<T, R>::value
>
#endif // defined(GENERATING_DOCUMENTATION)
{
};
#if defined(ASIO_HAS_VARIABLE_TEMPLATES)
template <typename T, typename R>
ASIO_CONSTEXPR const bool is_sender_to_v =
is_sender_to<T, R>::value;
#endif // defined(ASIO_HAS_VARIABLE_TEMPLATES)
#if defined(ASIO_HAS_CONCEPTS)
template <typename T, typename R>
ASIO_CONCEPT sender_to = is_sender_to<T, R>::value;
#define ASIO_EXECUTION_SENDER_TO(r) \
::asio::execution::sender_to<r>
#else // defined(ASIO_HAS_CONCEPTS)
#define ASIO_EXECUTION_SENDER_TO(r) typename
#endif // defined(ASIO_HAS_CONCEPTS)
/// The is_typed_sender trait detects whether a type T satisfies the
/// execution::typed_sender concept.
/**
* Class template @c is_typed_sender is a type trait that is derived from @c
* true_type if the type @c T meets the concept definition for a typed sender,
* otherwise @c false.
*/
template <typename T>
struct is_typed_sender :
#if defined(GENERATING_DOCUMENTATION)
integral_constant<bool, automatically_determined>
#else // defined(GENERATING_DOCUMENTATION)
integral_constant<bool,
is_sender<T>::value
&& detail::has_sender_types<
sender_traits<typename remove_cvref<T>::type> >::value
>
#endif // defined(GENERATING_DOCUMENTATION)
{
};
#if defined(ASIO_HAS_VARIABLE_TEMPLATES)
template <typename T>
ASIO_CONSTEXPR const bool is_typed_sender_v = is_typed_sender<T>::value;
#endif // defined(ASIO_HAS_VARIABLE_TEMPLATES)
#if defined(ASIO_HAS_CONCEPTS)
template <typename T>
ASIO_CONCEPT typed_sender = is_typed_sender<T>::value;
#define ASIO_EXECUTION_TYPED_SENDER \
::asio::execution::typed_sender
#else // defined(ASIO_HAS_CONCEPTS)
#define ASIO_EXECUTION_TYPED_SENDER typename
#endif // defined(ASIO_HAS_CONCEPTS)
} // namespace execution
} // namespace asio
#include "asio/detail/pop_options.hpp"
#include "asio/execution/connect.hpp"
#endif // ASIO_EXECUTION_SENDER_HPP