// // 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 ASIO_EXECUTION_OCCUPANCY_HPP #define ASIO_EXECUTION_OCCUPANCY_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/executor.hpp" #include "asio/execution/scheduler.hpp" #include "asio/execution/sender.hpp" #include "asio/is_applicable_property.hpp" #include "asio/traits/query_static_constexpr_member.hpp" #include "asio/traits/static_query.hpp" #include "asio/detail/push_options.hpp" 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 static constexpr bool is_applicable_property_v = is_executor_v || is_sender_v || is_scheduler_v; /// 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 struct occupancy_t { #if defined(ASIO_HAS_VARIABLE_TEMPLATES) # if defined(ASIO_NO_DEPRECATED) template ASIO_STATIC_CONSTEXPR(bool, is_applicable_property_v = ( is_executor::value)); # else // defined(ASIO_NO_DEPRECATED) template ASIO_STATIC_CONSTEXPR(bool, is_applicable_property_v = ( is_executor::value || conditional< is_executor::value, false_type, is_sender >::type::value || conditional< is_executor::value, false_type, is_scheduler >::type::value )); # endif // defined(ASIO_NO_DEPRECATED) #endif // defined(ASIO_HAS_VARIABLE_TEMPLATES) ASIO_STATIC_CONSTEXPR(bool, is_requirable = false); ASIO_STATIC_CONSTEXPR(bool, is_preferable = false); typedef std::size_t polymorphic_query_result_type; ASIO_CONSTEXPR occupancy_t() { } template struct static_proxy { #if defined(ASIO_HAS_DEDUCED_QUERY_STATIC_CONSTEXPR_MEMBER_TRAIT) struct type { template static constexpr auto query(ASIO_MOVE_ARG(P) p) noexcept( noexcept( conditional::type::query(ASIO_MOVE_CAST(P)(p)) ) ) -> decltype( conditional::type::query(ASIO_MOVE_CAST(P)(p)) ) { return T::query(ASIO_MOVE_CAST(P)(p)); } }; #else // defined(ASIO_HAS_DEDUCED_QUERY_STATIC_CONSTEXPR_MEMBER_TRAIT) typedef T type; #endif // defined(ASIO_HAS_DEDUCED_QUERY_STATIC_CONSTEXPR_MEMBER_TRAIT) }; template struct query_static_constexpr_member : traits::query_static_constexpr_member< typename static_proxy::type, occupancy_t> {}; #if defined(ASIO_HAS_DEDUCED_STATIC_QUERY_TRAIT) \ && defined(ASIO_HAS_SFINAE_VARIABLE_TEMPLATES) template static ASIO_CONSTEXPR typename query_static_constexpr_member::result_type static_query() ASIO_NOEXCEPT_IF(( query_static_constexpr_member::is_noexcept)) { return query_static_constexpr_member::value(); } template ())> static ASIO_CONSTEXPR const T static_query_v = occupancy_t::static_query(); #endif // defined(ASIO_HAS_DEDUCED_STATIC_QUERY_TRAIT) // && defined(ASIO_HAS_SFINAE_VARIABLE_TEMPLATES) #if !defined(ASIO_HAS_CONSTEXPR) static const occupancy_t instance; #endif // !defined(ASIO_HAS_CONSTEXPR) }; #if defined(ASIO_HAS_DEDUCED_STATIC_QUERY_TRAIT) \ && defined(ASIO_HAS_SFINAE_VARIABLE_TEMPLATES) template template const T occupancy_t::static_query_v; #endif // defined(ASIO_HAS_DEDUCED_STATIC_QUERY_TRAIT) // && defined(ASIO_HAS_SFINAE_VARIABLE_TEMPLATES) #if !defined(ASIO_HAS_CONSTEXPR) template const occupancy_t occupancy_t::instance; #endif } // namespace detail typedef detail::occupancy_t<> occupancy_t; #if defined(ASIO_HAS_CONSTEXPR) || defined(GENERATING_DOCUMENTATION) constexpr occupancy_t occupancy; #else // defined(ASIO_HAS_CONSTEXPR) || defined(GENERATING_DOCUMENTATION) namespace { static const occupancy_t& occupancy = occupancy_t::instance; } #endif } // namespace execution #if !defined(ASIO_HAS_VARIABLE_TEMPLATES) template struct is_applicable_property : integral_constant::value #if !defined(ASIO_NO_DEPRECATED) || conditional< execution::is_executor::value, false_type, execution::is_sender >::type::value || conditional< execution::is_executor::value, false_type, execution::is_scheduler >::type::value #endif // !defined(ASIO_NO_DEPRECATED) > { }; #endif // !defined(ASIO_HAS_VARIABLE_TEMPLATES) namespace traits { #if !defined(ASIO_HAS_DEDUCED_STATIC_QUERY_TRAIT) \ || !defined(ASIO_HAS_SFINAE_VARIABLE_TEMPLATES) template struct static_query:: query_static_constexpr_member::is_valid >::type> { ASIO_STATIC_CONSTEXPR(bool, is_valid = true); ASIO_STATIC_CONSTEXPR(bool, is_noexcept = true); typedef typename execution::detail::occupancy_t<0>:: query_static_constexpr_member::result_type result_type; static ASIO_CONSTEXPR result_type value() { return execution::detail::occupancy_t<0>:: query_static_constexpr_member::value(); } }; #endif // !defined(ASIO_HAS_DEDUCED_STATIC_QUERY_TRAIT) // || !defined(ASIO_HAS_SFINAE_VARIABLE_TEMPLATES) } // namespace traits #endif // defined(GENERATING_DOCUMENTATION) } // namespace asio #include "asio/detail/pop_options.hpp" #endif // ASIO_EXECUTION_OCCUPANCY_HPP