1//
2// execution/occupancy.hpp
3// ~~~~~~~~~~~~~~~~~~~~~~~
4//
5// Copyright (c) 2003-2024 Christopher M. Kohlhoff (chris at kohlhoff dot com)
6//
7// Distributed under the Boost Software License, Version 1.0. (See accompanying
8// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
9//
10
11#ifndef BOOST_ASIO_EXECUTION_OCCUPANCY_HPP
12#define BOOST_ASIO_EXECUTION_OCCUPANCY_HPP
13
14#if defined(_MSC_VER) && (_MSC_VER >= 1200)
15# pragma once
16#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
17
18#include <boost/asio/detail/config.hpp>
19#include <boost/asio/detail/type_traits.hpp>
20#include <boost/asio/execution/executor.hpp>
21#include <boost/asio/is_applicable_property.hpp>
22#include <boost/asio/traits/query_static_constexpr_member.hpp>
23#include <boost/asio/traits/static_query.hpp>
24
25#include <boost/asio/detail/push_options.hpp>
26
27namespace boost {
28namespace asio {
29
30#if defined(GENERATING_DOCUMENTATION)
31
32namespace execution {
33
34/// A property that gives an estimate of the number of execution agents that
35/// should occupy the associated execution context.
36struct occupancy_t
37{
38 /// The occupancy_t property applies to executors.
39 template <typename T>
40 static constexpr bool is_applicable_property_v = is_executor_v<T>;
41
42 /// The occupancy_t property cannot be required.
43 static constexpr bool is_requirable = false;
44
45 /// The occupancy_t property cannot be preferred.
46 static constexpr bool is_preferable = false;
47
48 /// The type returned by queries against an @c any_executor.
49 typedef std::size_t polymorphic_query_result_type;
50};
51
52/// A special value used for accessing the occupancy_t property.
53constexpr occupancy_t occupancy;
54
55} // namespace execution
56
57#else // defined(GENERATING_DOCUMENTATION)
58
59namespace execution {
60namespace detail {
61
62template <int I = 0>
63struct occupancy_t
64{
65#if defined(BOOST_ASIO_HAS_VARIABLE_TEMPLATES)
66 template <typename T>
67 static constexpr bool is_applicable_property_v = is_executor<T>::value;
68#endif // defined(BOOST_ASIO_HAS_VARIABLE_TEMPLATES)
69
70 static constexpr bool is_requirable = false;
71 static constexpr bool is_preferable = false;
72 typedef std::size_t polymorphic_query_result_type;
73
74 constexpr occupancy_t()
75 {
76 }
77
78 template <typename T>
79 struct static_proxy
80 {
81#if defined(BOOST_ASIO_HAS_DEDUCED_QUERY_STATIC_CONSTEXPR_MEMBER_TRAIT)
82 struct type
83 {
84 template <typename P>
85 static constexpr auto query(P&& p)
86 noexcept(
87 noexcept(
88 conditional_t<true, T, P>::query(static_cast<P&&>(p))
89 )
90 )
91 -> decltype(
92 conditional_t<true, T, P>::query(static_cast<P&&>(p))
93 )
94 {
95 return T::query(static_cast<P&&>(p));
96 }
97 };
98#else // defined(BOOST_ASIO_HAS_DEDUCED_QUERY_STATIC_CONSTEXPR_MEMBER_TRAIT)
99 typedef T type;
100#endif // defined(BOOST_ASIO_HAS_DEDUCED_QUERY_STATIC_CONSTEXPR_MEMBER_TRAIT)
101 };
102
103 template <typename T>
104 struct query_static_constexpr_member :
105 traits::query_static_constexpr_member<
106 typename static_proxy<T>::type, occupancy_t> {};
107
108#if defined(BOOST_ASIO_HAS_DEDUCED_STATIC_QUERY_TRAIT) \
109 && defined(BOOST_ASIO_HAS_SFINAE_VARIABLE_TEMPLATES)
110 template <typename T>
111 static constexpr typename query_static_constexpr_member<T>::result_type
112 static_query()
113 noexcept(query_static_constexpr_member<T>::is_noexcept)
114 {
115 return query_static_constexpr_member<T>::value();
116 }
117
118 template <typename E, typename T = decltype(occupancy_t::static_query<E>())>
119 static constexpr const T static_query_v = occupancy_t::static_query<E>();
120#endif // defined(BOOST_ASIO_HAS_DEDUCED_STATIC_QUERY_TRAIT)
121 // && defined(BOOST_ASIO_HAS_SFINAE_VARIABLE_TEMPLATES)
122};
123
124#if defined(BOOST_ASIO_HAS_DEDUCED_STATIC_QUERY_TRAIT) \
125 && defined(BOOST_ASIO_HAS_SFINAE_VARIABLE_TEMPLATES)
126template <int I> template <typename E, typename T>
127const T occupancy_t<I>::static_query_v;
128#endif // defined(BOOST_ASIO_HAS_DEDUCED_STATIC_QUERY_TRAIT)
129 // && defined(BOOST_ASIO_HAS_SFINAE_VARIABLE_TEMPLATES)
130
131} // namespace detail
132
133typedef detail::occupancy_t<> occupancy_t;
134
135constexpr occupancy_t occupancy;
136
137} // namespace execution
138
139#if !defined(BOOST_ASIO_HAS_VARIABLE_TEMPLATES)
140
141template <typename T>
142struct is_applicable_property<T, execution::occupancy_t>
143 : integral_constant<bool, execution::is_executor<T>::value>
144{
145};
146
147#endif // !defined(BOOST_ASIO_HAS_VARIABLE_TEMPLATES)
148
149namespace traits {
150
151#if !defined(BOOST_ASIO_HAS_DEDUCED_STATIC_QUERY_TRAIT) \
152 || !defined(BOOST_ASIO_HAS_SFINAE_VARIABLE_TEMPLATES)
153
154template <typename T>
155struct static_query<T, execution::occupancy_t,
156 enable_if_t<
157 execution::detail::occupancy_t<0>::
158 query_static_constexpr_member<T>::is_valid
159 >>
160{
161 static constexpr bool is_valid = true;
162 static constexpr bool is_noexcept = true;
163
164 typedef typename execution::detail::occupancy_t<0>::
165 query_static_constexpr_member<T>::result_type result_type;
166
167 static constexpr result_type value()
168 {
169 return execution::detail::occupancy_t<0>::
170 query_static_constexpr_member<T>::value();
171 }
172};
173
174#endif // !defined(BOOST_ASIO_HAS_DEDUCED_STATIC_QUERY_TRAIT)
175 // || !defined(BOOST_ASIO_HAS_SFINAE_VARIABLE_TEMPLATES)
176
177} // namespace traits
178
179#endif // defined(GENERATING_DOCUMENTATION)
180
181} // namespace asio
182} // namespace boost
183
184#include <boost/asio/detail/pop_options.hpp>
185
186#endif // BOOST_ASIO_EXECUTION_OCCUPANCY_HPP
187

source code of boost/libs/asio/include/boost/asio/execution/occupancy.hpp