occupancy.hpp
6.98 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
//
// execution/occupancy.hpp
// ~~~~~~~~~~~~~~~~~~~~~~~
//
// Copyright (c) 2003-2022 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 BOOST_ASIO_EXECUTION_OCCUPANCY_HPP
#define BOOST_ASIO_EXECUTION_OCCUPANCY_HPP
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
# pragma once
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
#include <boost/asio/detail/config.hpp>
#include <boost/asio/detail/type_traits.hpp>
#include <boost/asio/execution/executor.hpp>
#include <boost/asio/execution/scheduler.hpp>
#include <boost/asio/execution/sender.hpp>
#include <boost/asio/is_applicable_property.hpp>
#include <boost/asio/traits/query_static_constexpr_member.hpp>
#include <boost/asio/traits/static_query.hpp>
#include <boost/asio/detail/push_options.hpp>
namespace boost {
namespace asio {
#if defined(GENERATING_DOCUMENTATION)
namespace execution {
/// A property that gives an estimate of the number of execution agents that
/// should occupy the associated execution context.
struct occupancy_t
{
/// The occupancy_t property applies to executors, senders, and schedulers.
template <typename T>
static constexpr bool is_applicable_property_v =
is_executor_v<T> || is_sender_v<T> || is_scheduler_v<T>;
/// The occupancy_t property cannot be required.
static constexpr bool is_requirable = false;
/// The occupancy_t property cannot be preferred.
static constexpr bool is_preferable = false;
/// The type returned by queries against an @c any_executor.
typedef std::size_t polymorphic_query_result_type;
};
/// A special value used for accessing the occupancy_t property.
constexpr occupancy_t occupancy;
} // namespace execution
#else // defined(GENERATING_DOCUMENTATION)
namespace execution {
namespace detail {
template <int I = 0>
struct occupancy_t
{
#if defined(BOOST_ASIO_HAS_VARIABLE_TEMPLATES)
# if defined(BOOST_ASIO_NO_DEPRECATED)
template <typename T>
BOOST_ASIO_STATIC_CONSTEXPR(bool,
is_applicable_property_v = (
is_executor<T>::value));
# else // defined(BOOST_ASIO_NO_DEPRECATED)
template <typename T>
BOOST_ASIO_STATIC_CONSTEXPR(bool,
is_applicable_property_v = (
is_executor<T>::value
|| conditional<
is_executor<T>::value,
false_type,
is_sender<T>
>::type::value
|| conditional<
is_executor<T>::value,
false_type,
is_scheduler<T>
>::type::value
));
# endif // defined(BOOST_ASIO_NO_DEPRECATED)
#endif // defined(BOOST_ASIO_HAS_VARIABLE_TEMPLATES)
BOOST_ASIO_STATIC_CONSTEXPR(bool, is_requirable = false);
BOOST_ASIO_STATIC_CONSTEXPR(bool, is_preferable = false);
typedef std::size_t polymorphic_query_result_type;
BOOST_ASIO_CONSTEXPR occupancy_t()
{
}
template <typename T>
struct static_proxy
{
#if defined(BOOST_ASIO_HAS_DEDUCED_QUERY_STATIC_CONSTEXPR_MEMBER_TRAIT)
struct type
{
template <typename P>
static constexpr auto query(BOOST_ASIO_MOVE_ARG(P) p)
noexcept(
noexcept(
conditional<true, T, P>::type::query(BOOST_ASIO_MOVE_CAST(P)(p))
)
)
-> decltype(
conditional<true, T, P>::type::query(BOOST_ASIO_MOVE_CAST(P)(p))
)
{
return T::query(BOOST_ASIO_MOVE_CAST(P)(p));
}
};
#else // defined(BOOST_ASIO_HAS_DEDUCED_QUERY_STATIC_CONSTEXPR_MEMBER_TRAIT)
typedef T type;
#endif // defined(BOOST_ASIO_HAS_DEDUCED_QUERY_STATIC_CONSTEXPR_MEMBER_TRAIT)
};
template <typename T>
struct query_static_constexpr_member :
traits::query_static_constexpr_member<
typename static_proxy<T>::type, occupancy_t> {};
#if defined(BOOST_ASIO_HAS_DEDUCED_STATIC_QUERY_TRAIT) \
&& defined(BOOST_ASIO_HAS_SFINAE_VARIABLE_TEMPLATES)
template <typename T>
static BOOST_ASIO_CONSTEXPR
typename query_static_constexpr_member<T>::result_type
static_query()
BOOST_ASIO_NOEXCEPT_IF((
query_static_constexpr_member<T>::is_noexcept))
{
return query_static_constexpr_member<T>::value();
}
template <typename E, typename T = decltype(occupancy_t::static_query<E>())>
static BOOST_ASIO_CONSTEXPR const T static_query_v
= occupancy_t::static_query<E>();
#endif // defined(BOOST_ASIO_HAS_DEDUCED_STATIC_QUERY_TRAIT)
// && defined(BOOST_ASIO_HAS_SFINAE_VARIABLE_TEMPLATES)
#if !defined(BOOST_ASIO_HAS_CONSTEXPR)
static const occupancy_t instance;
#endif // !defined(BOOST_ASIO_HAS_CONSTEXPR)
};
#if defined(BOOST_ASIO_HAS_DEDUCED_STATIC_QUERY_TRAIT) \
&& defined(BOOST_ASIO_HAS_SFINAE_VARIABLE_TEMPLATES)
template <int I> template <typename E, typename T>
const T occupancy_t<I>::static_query_v;
#endif // defined(BOOST_ASIO_HAS_DEDUCED_STATIC_QUERY_TRAIT)
// && defined(BOOST_ASIO_HAS_SFINAE_VARIABLE_TEMPLATES)
#if !defined(BOOST_ASIO_HAS_CONSTEXPR)
template <int I>
const occupancy_t<I> occupancy_t<I>::instance;
#endif
} // namespace detail
typedef detail::occupancy_t<> occupancy_t;
#if defined(BOOST_ASIO_HAS_CONSTEXPR) || defined(GENERATING_DOCUMENTATION)
constexpr occupancy_t occupancy;
#else // defined(BOOST_ASIO_HAS_CONSTEXPR) || defined(GENERATING_DOCUMENTATION)
namespace { static const occupancy_t& occupancy = occupancy_t::instance; }
#endif
} // namespace execution
#if !defined(BOOST_ASIO_HAS_VARIABLE_TEMPLATES)
template <typename T>
struct is_applicable_property<T, execution::occupancy_t>
: integral_constant<bool,
execution::is_executor<T>::value
#if !defined(BOOST_ASIO_NO_DEPRECATED)
|| conditional<
execution::is_executor<T>::value,
false_type,
execution::is_sender<T>
>::type::value
|| conditional<
execution::is_executor<T>::value,
false_type,
execution::is_scheduler<T>
>::type::value
#endif // !defined(BOOST_ASIO_NO_DEPRECATED)
>
{
};
#endif // !defined(BOOST_ASIO_HAS_VARIABLE_TEMPLATES)
namespace traits {
#if !defined(BOOST_ASIO_HAS_DEDUCED_STATIC_QUERY_TRAIT) \
|| !defined(BOOST_ASIO_HAS_SFINAE_VARIABLE_TEMPLATES)
template <typename T>
struct static_query<T, execution::occupancy_t,
typename enable_if<
execution::detail::occupancy_t<0>::
query_static_constexpr_member<T>::is_valid
>::type>
{
BOOST_ASIO_STATIC_CONSTEXPR(bool, is_valid = true);
BOOST_ASIO_STATIC_CONSTEXPR(bool, is_noexcept = true);
typedef typename execution::detail::occupancy_t<0>::
query_static_constexpr_member<T>::result_type result_type;
static BOOST_ASIO_CONSTEXPR result_type value()
{
return execution::detail::occupancy_t<0>::
query_static_constexpr_member<T>::value();
}
};
#endif // !defined(BOOST_ASIO_HAS_DEDUCED_STATIC_QUERY_TRAIT)
// || !defined(BOOST_ASIO_HAS_SFINAE_VARIABLE_TEMPLATES)
} // namespace traits
#endif // defined(GENERATING_DOCUMENTATION)
} // namespace asio
} // namespace boost
#include <boost/asio/detail/pop_options.hpp>
#endif // BOOST_ASIO_EXECUTION_OCCUPANCY_HPP