occupancy.hpp 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  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. #ifndef BOOST_ASIO_EXECUTION_OCCUPANCY_HPP
  11. #define BOOST_ASIO_EXECUTION_OCCUPANCY_HPP
  12. #if defined(_MSC_VER) && (_MSC_VER >= 1200)
  13. # pragma once
  14. #endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
  15. #include <boost/asio/detail/config.hpp>
  16. #include <boost/asio/detail/type_traits.hpp>
  17. #include <boost/asio/execution/executor.hpp>
  18. #include <boost/asio/is_applicable_property.hpp>
  19. #include <boost/asio/traits/query_static_constexpr_member.hpp>
  20. #include <boost/asio/traits/static_query.hpp>
  21. #include <boost/asio/detail/push_options.hpp>
  22. namespace boost {
  23. namespace asio {
  24. #if defined(GENERATING_DOCUMENTATION)
  25. namespace execution {
  26. /// A property that gives an estimate of the number of execution agents that
  27. /// should occupy the associated execution context.
  28. struct occupancy_t
  29. {
  30. /// The occupancy_t property applies to executors.
  31. template <typename T>
  32. static constexpr bool is_applicable_property_v = is_executor_v<T>;
  33. /// The occupancy_t property cannot be required.
  34. static constexpr bool is_requirable = false;
  35. /// The occupancy_t property cannot be preferred.
  36. static constexpr bool is_preferable = false;
  37. /// The type returned by queries against an @c any_executor.
  38. typedef std::size_t polymorphic_query_result_type;
  39. };
  40. /// A special value used for accessing the occupancy_t property.
  41. constexpr occupancy_t occupancy;
  42. } // namespace execution
  43. #else // defined(GENERATING_DOCUMENTATION)
  44. namespace execution {
  45. namespace detail {
  46. template <int I = 0>
  47. struct occupancy_t
  48. {
  49. #if defined(BOOST_ASIO_HAS_VARIABLE_TEMPLATES)
  50. template <typename T>
  51. static constexpr bool is_applicable_property_v = is_executor<T>::value;
  52. #endif // defined(BOOST_ASIO_HAS_VARIABLE_TEMPLATES)
  53. static constexpr bool is_requirable = false;
  54. static constexpr bool is_preferable = false;
  55. typedef std::size_t polymorphic_query_result_type;
  56. constexpr occupancy_t()
  57. {
  58. }
  59. template <typename T>
  60. struct static_proxy
  61. {
  62. #if defined(BOOST_ASIO_HAS_DEDUCED_QUERY_STATIC_CONSTEXPR_MEMBER_TRAIT)
  63. struct type
  64. {
  65. template <typename P>
  66. static constexpr auto query(P&& p)
  67. noexcept(
  68. noexcept(
  69. conditional_t<true, T, P>::query(static_cast<P&&>(p))
  70. )
  71. )
  72. -> decltype(
  73. conditional_t<true, T, P>::query(static_cast<P&&>(p))
  74. )
  75. {
  76. return T::query(static_cast<P&&>(p));
  77. }
  78. };
  79. #else // defined(BOOST_ASIO_HAS_DEDUCED_QUERY_STATIC_CONSTEXPR_MEMBER_TRAIT)
  80. typedef T type;
  81. #endif // defined(BOOST_ASIO_HAS_DEDUCED_QUERY_STATIC_CONSTEXPR_MEMBER_TRAIT)
  82. };
  83. template <typename T>
  84. struct query_static_constexpr_member :
  85. traits::query_static_constexpr_member<
  86. typename static_proxy<T>::type, occupancy_t> {};
  87. #if defined(BOOST_ASIO_HAS_DEDUCED_STATIC_QUERY_TRAIT) \
  88. && defined(BOOST_ASIO_HAS_SFINAE_VARIABLE_TEMPLATES)
  89. template <typename T>
  90. static constexpr typename query_static_constexpr_member<T>::result_type
  91. static_query()
  92. noexcept(query_static_constexpr_member<T>::is_noexcept)
  93. {
  94. return query_static_constexpr_member<T>::value();
  95. }
  96. template <typename E, typename T = decltype(occupancy_t::static_query<E>())>
  97. static constexpr const T static_query_v = occupancy_t::static_query<E>();
  98. #endif // defined(BOOST_ASIO_HAS_DEDUCED_STATIC_QUERY_TRAIT)
  99. // && defined(BOOST_ASIO_HAS_SFINAE_VARIABLE_TEMPLATES)
  100. };
  101. #if defined(BOOST_ASIO_HAS_DEDUCED_STATIC_QUERY_TRAIT) \
  102. && defined(BOOST_ASIO_HAS_SFINAE_VARIABLE_TEMPLATES)
  103. template <int I> template <typename E, typename T>
  104. const T occupancy_t<I>::static_query_v;
  105. #endif // defined(BOOST_ASIO_HAS_DEDUCED_STATIC_QUERY_TRAIT)
  106. // && defined(BOOST_ASIO_HAS_SFINAE_VARIABLE_TEMPLATES)
  107. } // namespace detail
  108. typedef detail::occupancy_t<> occupancy_t;
  109. BOOST_ASIO_INLINE_VARIABLE constexpr occupancy_t occupancy;
  110. } // namespace execution
  111. #if !defined(BOOST_ASIO_HAS_VARIABLE_TEMPLATES)
  112. template <typename T>
  113. struct is_applicable_property<T, execution::occupancy_t>
  114. : integral_constant<bool, execution::is_executor<T>::value>
  115. {
  116. };
  117. #endif // !defined(BOOST_ASIO_HAS_VARIABLE_TEMPLATES)
  118. namespace traits {
  119. #if !defined(BOOST_ASIO_HAS_DEDUCED_STATIC_QUERY_TRAIT) \
  120. || !defined(BOOST_ASIO_HAS_SFINAE_VARIABLE_TEMPLATES)
  121. template <typename T>
  122. struct static_query<T, execution::occupancy_t,
  123. enable_if_t<
  124. execution::detail::occupancy_t<0>::
  125. query_static_constexpr_member<T>::is_valid
  126. >>
  127. {
  128. static constexpr bool is_valid = true;
  129. static constexpr bool is_noexcept = true;
  130. typedef typename execution::detail::occupancy_t<0>::
  131. query_static_constexpr_member<T>::result_type result_type;
  132. static constexpr result_type value()
  133. {
  134. return execution::detail::occupancy_t<0>::
  135. query_static_constexpr_member<T>::value();
  136. }
  137. };
  138. #endif // !defined(BOOST_ASIO_HAS_DEDUCED_STATIC_QUERY_TRAIT)
  139. // || !defined(BOOST_ASIO_HAS_SFINAE_VARIABLE_TEMPLATES)
  140. } // namespace traits
  141. #endif // defined(GENERATING_DOCUMENTATION)
  142. } // namespace asio
  143. } // namespace boost
  144. #include <boost/asio/detail/pop_options.hpp>
  145. #endif // BOOST_ASIO_EXECUTION_OCCUPANCY_HPP