executor.hpp
6.63 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
//
// execution/executor.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_EXECUTOR_HPP
#define ASIO_EXECUTION_EXECUTOR_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/execute.hpp"
#include "asio/execution/invocable_archetype.hpp"
#include "asio/traits/equality_comparable.hpp"
#if defined(ASIO_HAS_DEDUCED_EXECUTE_FREE_TRAIT) \
&& defined(ASIO_HAS_DEDUCED_EXECUTE_MEMBER_TRAIT) \
&& defined(ASIO_HAS_DEDUCED_EQUALITY_COMPARABLE_TRAIT)
# define ASIO_HAS_DEDUCED_EXECUTION_IS_EXECUTOR_TRAIT 1
#endif // defined(ASIO_HAS_DEDUCED_EXECUTE_FREE_TRAIT)
// && defined(ASIO_HAS_DEDUCED_EXECUTE_MEMBER_TRAIT)
// && defined(ASIO_HAS_DEDUCED_EQUALITY_COMPARABLE_TRAIT)
#include "asio/detail/push_options.hpp"
namespace asio {
namespace execution {
namespace detail {
template <typename T, typename F>
struct is_executor_of_impl_base :
integral_constant<bool,
conditional<true, true_type,
typename result_of<typename decay<F>::type&()>::type
>::type::value
&& is_constructible<typename decay<F>::type, F>::value
&& is_move_constructible<typename decay<F>::type>::value
#if defined(ASIO_HAS_NOEXCEPT)
&& is_nothrow_copy_constructible<T>::value
&& is_nothrow_destructible<T>::value
#else // defined(ASIO_HAS_NOEXCEPT)
&& is_copy_constructible<T>::value
&& is_destructible<T>::value
#endif // defined(ASIO_HAS_NOEXCEPT)
&& traits::equality_comparable<T>::is_valid
&& traits::equality_comparable<T>::is_noexcept
>
{
};
template <typename T, typename F>
struct is_executor_of_impl :
conditional<
can_execute<typename add_const<T>::type, F>::value,
is_executor_of_impl_base<T, F>,
false_type
>::type
{
};
template <typename T, typename = void>
struct executor_shape
{
typedef std::size_t type;
};
template <typename T>
struct executor_shape<T,
typename void_type<
typename T::shape_type
>::type>
{
typedef typename T::shape_type type;
};
template <typename T, typename Default, typename = void>
struct executor_index
{
typedef Default type;
};
template <typename T, typename Default>
struct executor_index<T, Default,
typename void_type<
typename T::index_type
>::type>
{
typedef typename T::index_type type;
};
} // namespace detail
/// The is_executor trait detects whether a type T satisfies the
/// execution::executor concept.
/**
* Class template @c is_executor is a UnaryTypeTrait that is derived from @c
* true_type if the type @c T meets the concept definition for an executor,
* otherwise @c false_type.
*/
template <typename T>
struct is_executor :
#if defined(GENERATING_DOCUMENTATION)
integral_constant<bool, automatically_determined>
#else // defined(GENERATING_DOCUMENTATION)
detail::is_executor_of_impl<T, invocable_archetype>
#endif // defined(GENERATING_DOCUMENTATION)
{
};
#if defined(ASIO_HAS_VARIABLE_TEMPLATES)
template <typename T>
ASIO_CONSTEXPR const bool is_executor_v = is_executor<T>::value;
#endif // defined(ASIO_HAS_VARIABLE_TEMPLATES)
#if defined(ASIO_HAS_CONCEPTS)
template <typename T>
ASIO_CONCEPT executor = is_executor<T>::value;
#define ASIO_EXECUTION_EXECUTOR ::asio::execution::executor
#else // defined(ASIO_HAS_CONCEPTS)
#define ASIO_EXECUTION_EXECUTOR typename
#endif // defined(ASIO_HAS_CONCEPTS)
/// The is_executor_of trait detects whether a type T satisfies the
/// execution::executor_of concept for some set of value arguments.
/**
* Class template @c is_executor_of is a type trait that is derived from @c
* true_type if the type @c T meets the concept definition for an executor
* that is invocable with a function object of type @c F, otherwise @c
* false_type.
*/
template <typename T, typename F>
struct is_executor_of :
#if defined(GENERATING_DOCUMENTATION)
integral_constant<bool, automatically_determined>
#else // defined(GENERATING_DOCUMENTATION)
integral_constant<bool,
is_executor<T>::value && detail::is_executor_of_impl<T, F>::value
>
#endif // defined(GENERATING_DOCUMENTATION)
{
};
#if defined(ASIO_HAS_VARIABLE_TEMPLATES)
template <typename T, typename F>
ASIO_CONSTEXPR const bool is_executor_of_v =
is_executor_of<T, F>::value;
#endif // defined(ASIO_HAS_VARIABLE_TEMPLATES)
#if defined(ASIO_HAS_CONCEPTS)
template <typename T, typename F>
ASIO_CONCEPT executor_of = is_executor_of<T, F>::value;
#define ASIO_EXECUTION_EXECUTOR_OF(f) \
::asio::execution::executor_of<f>
#else // defined(ASIO_HAS_CONCEPTS)
#define ASIO_EXECUTION_EXECUTOR_OF typename
#endif // defined(ASIO_HAS_CONCEPTS)
/// The executor_shape trait detects the type used by an executor to represent
/// the shape of a bulk operation.
/**
* Class template @c executor_shape is a type trait with a nested type alias
* @c type whose type is @c T::shape_type if @c T::shape_type is valid,
* otherwise @c std::size_t.
*/
template <typename T>
struct executor_shape
#if !defined(GENERATING_DOCUMENTATION)
: detail::executor_shape<T>
#endif // !defined(GENERATING_DOCUMENTATION)
{
#if defined(GENERATING_DOCUMENTATION)
/// @c T::shape_type if @c T::shape_type is valid, otherwise @c std::size_t.
typedef automatically_determined type;
#endif // defined(GENERATING_DOCUMENTATION)
};
#if defined(ASIO_HAS_ALIAS_TEMPLATES)
template <typename T>
using executor_shape_t = typename executor_shape<T>::type;
#endif // defined(ASIO_HAS_ALIAS_TEMPLATES)
/// The executor_index trait detects the type used by an executor to represent
/// an index within a bulk operation.
/**
* Class template @c executor_index is a type trait with a nested type alias
* @c type whose type is @c T::index_type if @c T::index_type is valid,
* otherwise @c executor_shape_t<T>.
*/
template <typename T>
struct executor_index
#if !defined(GENERATING_DOCUMENTATION)
: detail::executor_index<T, typename executor_shape<T>::type>
#endif // !defined(GENERATING_DOCUMENTATION)
{
#if defined(GENERATING_DOCUMENTATION)
/// @c T::index_type if @c T::index_type is valid, otherwise
/// @c executor_shape_t<T>.
typedef automatically_determined type;
#endif // defined(GENERATING_DOCUMENTATION)
};
#if defined(ASIO_HAS_ALIAS_TEMPLATES)
template <typename T>
using executor_index_t = typename executor_index<T>::type;
#endif // defined(ASIO_HAS_ALIAS_TEMPLATES)
} // namespace execution
} // namespace asio
#include "asio/detail/pop_options.hpp"
#endif // ASIO_EXECUTION_EXECUTOR_HPP