Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2024-11-16 09:05:21

0001 //
0002 // execution/occupancy.hpp
0003 // ~~~~~~~~~~~~~~~~~~~~~~~
0004 //
0005 // Copyright (c) 2003-2023 Christopher M. Kohlhoff (chris at kohlhoff dot com)
0006 //
0007 // Distributed under the Boost Software License, Version 1.0. (See accompanying
0008 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
0009 //
0010 
0011 #ifndef BOOST_ASIO_EXECUTION_OCCUPANCY_HPP
0012 #define BOOST_ASIO_EXECUTION_OCCUPANCY_HPP
0013 
0014 #if defined(_MSC_VER) && (_MSC_VER >= 1200)
0015 # pragma once
0016 #endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
0017 
0018 #include <boost/asio/detail/config.hpp>
0019 #include <boost/asio/detail/type_traits.hpp>
0020 #include <boost/asio/execution/executor.hpp>
0021 #include <boost/asio/is_applicable_property.hpp>
0022 #include <boost/asio/traits/query_static_constexpr_member.hpp>
0023 #include <boost/asio/traits/static_query.hpp>
0024 
0025 #include <boost/asio/detail/push_options.hpp>
0026 
0027 namespace boost {
0028 namespace asio {
0029 
0030 #if defined(GENERATING_DOCUMENTATION)
0031 
0032 namespace execution {
0033 
0034 /// A property that gives an estimate of the number of execution agents that
0035 /// should occupy the associated execution context.
0036 struct occupancy_t
0037 {
0038   /// The occupancy_t property applies to executors.
0039   template <typename T>
0040   static constexpr bool is_applicable_property_v = is_executor_v<T>;
0041 
0042   /// The occupancy_t property cannot be required.
0043   static constexpr bool is_requirable = false;
0044 
0045   /// The occupancy_t property cannot be preferred.
0046   static constexpr bool is_preferable = false;
0047 
0048   /// The type returned by queries against an @c any_executor.
0049   typedef std::size_t polymorphic_query_result_type;
0050 };
0051 
0052 /// A special value used for accessing the occupancy_t property.
0053 constexpr occupancy_t occupancy;
0054 
0055 } // namespace execution
0056 
0057 #else // defined(GENERATING_DOCUMENTATION)
0058 
0059 namespace execution {
0060 namespace detail {
0061 
0062 template <int I = 0>
0063 struct occupancy_t
0064 {
0065 #if defined(BOOST_ASIO_HAS_VARIABLE_TEMPLATES)
0066   template <typename T>
0067   static constexpr bool is_applicable_property_v = is_executor<T>::value;
0068 #endif // defined(BOOST_ASIO_HAS_VARIABLE_TEMPLATES)
0069 
0070   static constexpr bool is_requirable = false;
0071   static constexpr bool is_preferable = false;
0072   typedef std::size_t polymorphic_query_result_type;
0073 
0074   constexpr occupancy_t()
0075   {
0076   }
0077 
0078   template <typename T>
0079   struct static_proxy
0080   {
0081 #if defined(BOOST_ASIO_HAS_DEDUCED_QUERY_STATIC_CONSTEXPR_MEMBER_TRAIT)
0082     struct type
0083     {
0084       template <typename P>
0085       static constexpr auto query(P&& p)
0086         noexcept(
0087           noexcept(
0088             conditional_t<true, T, P>::query(static_cast<P&&>(p))
0089           )
0090         )
0091         -> decltype(
0092           conditional_t<true, T, P>::query(static_cast<P&&>(p))
0093         )
0094       {
0095         return T::query(static_cast<P&&>(p));
0096       }
0097     };
0098 #else // defined(BOOST_ASIO_HAS_DEDUCED_QUERY_STATIC_CONSTEXPR_MEMBER_TRAIT)
0099     typedef T type;
0100 #endif // defined(BOOST_ASIO_HAS_DEDUCED_QUERY_STATIC_CONSTEXPR_MEMBER_TRAIT)
0101   };
0102 
0103   template <typename T>
0104   struct query_static_constexpr_member :
0105     traits::query_static_constexpr_member<
0106       typename static_proxy<T>::type, occupancy_t> {};
0107 
0108 #if defined(BOOST_ASIO_HAS_DEDUCED_STATIC_QUERY_TRAIT) \
0109   && defined(BOOST_ASIO_HAS_SFINAE_VARIABLE_TEMPLATES)
0110   template <typename T>
0111   static constexpr typename query_static_constexpr_member<T>::result_type
0112   static_query()
0113     noexcept(query_static_constexpr_member<T>::is_noexcept)
0114   {
0115     return query_static_constexpr_member<T>::value();
0116   }
0117 
0118   template <typename E, typename T = decltype(occupancy_t::static_query<E>())>
0119   static constexpr const T static_query_v = occupancy_t::static_query<E>();
0120 #endif // defined(BOOST_ASIO_HAS_DEDUCED_STATIC_QUERY_TRAIT)
0121        //   && defined(BOOST_ASIO_HAS_SFINAE_VARIABLE_TEMPLATES)
0122 };
0123 
0124 #if defined(BOOST_ASIO_HAS_DEDUCED_STATIC_QUERY_TRAIT) \
0125   && defined(BOOST_ASIO_HAS_SFINAE_VARIABLE_TEMPLATES)
0126 template <int I> template <typename E, typename T>
0127 const T occupancy_t<I>::static_query_v;
0128 #endif // defined(BOOST_ASIO_HAS_DEDUCED_STATIC_QUERY_TRAIT)
0129        //   && defined(BOOST_ASIO_HAS_SFINAE_VARIABLE_TEMPLATES)
0130 
0131 } // namespace detail
0132 
0133 typedef detail::occupancy_t<> occupancy_t;
0134 
0135 constexpr occupancy_t occupancy;
0136 
0137 } // namespace execution
0138 
0139 #if !defined(BOOST_ASIO_HAS_VARIABLE_TEMPLATES)
0140 
0141 template <typename T>
0142 struct is_applicable_property<T, execution::occupancy_t>
0143   : integral_constant<bool, execution::is_executor<T>::value>
0144 {
0145 };
0146 
0147 #endif // !defined(BOOST_ASIO_HAS_VARIABLE_TEMPLATES)
0148 
0149 namespace traits {
0150 
0151 #if !defined(BOOST_ASIO_HAS_DEDUCED_STATIC_QUERY_TRAIT) \
0152   || !defined(BOOST_ASIO_HAS_SFINAE_VARIABLE_TEMPLATES)
0153 
0154 template <typename T>
0155 struct static_query<T, execution::occupancy_t,
0156   enable_if_t<
0157     execution::detail::occupancy_t<0>::
0158       query_static_constexpr_member<T>::is_valid
0159   >>
0160 {
0161   static constexpr bool is_valid = true;
0162   static constexpr bool is_noexcept = true;
0163 
0164   typedef typename execution::detail::occupancy_t<0>::
0165     query_static_constexpr_member<T>::result_type result_type;
0166 
0167   static constexpr result_type value()
0168   {
0169     return execution::detail::occupancy_t<0>::
0170       query_static_constexpr_member<T>::value();
0171   }
0172 };
0173 
0174 #endif // !defined(BOOST_ASIO_HAS_DEDUCED_STATIC_QUERY_TRAIT)
0175        //   || !defined(BOOST_ASIO_HAS_SFINAE_VARIABLE_TEMPLATES)
0176 
0177 } // namespace traits
0178 
0179 #endif // defined(GENERATING_DOCUMENTATION)
0180 
0181 } // namespace asio
0182 } // namespace boost
0183 
0184 #include <boost/asio/detail/pop_options.hpp>
0185 
0186 #endif // BOOST_ASIO_EXECUTION_OCCUPANCY_HPP