Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-12-16 09:43:17

0001 //
0002 // execution/context.hpp
0003 // ~~~~~~~~~~~~~~~~~~~~~
0004 //
0005 // Copyright (c) 2003-2025 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_CONTEXT2_HPP
0012 #define BOOST_ASIO_EXECUTION_CONTEXT2_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 #if defined(BOOST_ASIO_HAS_STD_ANY)
0026 # include <any>
0027 #endif // defined(BOOST_ASIO_HAS_STD_ANY)
0028 
0029 #include <boost/asio/detail/push_options.hpp>
0030 
0031 namespace boost {
0032 namespace asio {
0033 
0034 #if defined(GENERATING_DOCUMENTATION)
0035 
0036 namespace execution {
0037 
0038 /// A property that is used to obtain the execution context that is associated
0039 /// with an executor.
0040 struct context_t
0041 {
0042   /// The context_t property applies to executors.
0043   template <typename T>
0044   static constexpr bool is_applicable_property_v = is_executor_v<T>;
0045 
0046   /// The context_t property cannot be required.
0047   static constexpr bool is_requirable = false;
0048 
0049   /// The context_t property cannot be preferred.
0050   static constexpr bool is_preferable = false;
0051 
0052   /// The type returned by queries against an @c any_executor.
0053   typedef std::any polymorphic_query_result_type;
0054 };
0055 
0056 /// A special value used for accessing the context_t property.
0057 constexpr context_t context;
0058 
0059 } // namespace execution
0060 
0061 #else // defined(GENERATING_DOCUMENTATION)
0062 
0063 namespace execution {
0064 namespace detail {
0065 
0066 template <int I = 0>
0067 struct context_t
0068 {
0069 #if defined(BOOST_ASIO_HAS_VARIABLE_TEMPLATES)
0070   template <typename T>
0071   static constexpr bool is_applicable_property_v = is_executor<T>::value;
0072 #endif // defined(BOOST_ASIO_HAS_VARIABLE_TEMPLATES)
0073 
0074   static constexpr bool is_requirable = false;
0075   static constexpr bool is_preferable = false;
0076 
0077 #if defined(BOOST_ASIO_HAS_STD_ANY)
0078   typedef std::any polymorphic_query_result_type;
0079 #endif // defined(BOOST_ASIO_HAS_STD_ANY)
0080 
0081   constexpr context_t()
0082   {
0083   }
0084 
0085   template <typename T>
0086   struct static_proxy
0087   {
0088 #if defined(BOOST_ASIO_HAS_DEDUCED_QUERY_STATIC_CONSTEXPR_MEMBER_TRAIT)
0089     struct type
0090     {
0091       template <typename P>
0092       static constexpr auto query(P&& p)
0093         noexcept(
0094           noexcept(
0095             conditional_t<true, T, P>::query(static_cast<P&&>(p))
0096           )
0097         )
0098         -> decltype(
0099           conditional_t<true, T, P>::query(static_cast<P&&>(p))
0100         )
0101       {
0102         return T::query(static_cast<P&&>(p));
0103       }
0104     };
0105 #else // defined(BOOST_ASIO_HAS_DEDUCED_QUERY_STATIC_CONSTEXPR_MEMBER_TRAIT)
0106     typedef T type;
0107 #endif // defined(BOOST_ASIO_HAS_DEDUCED_QUERY_STATIC_CONSTEXPR_MEMBER_TRAIT)
0108   };
0109 
0110   template <typename T>
0111   struct query_static_constexpr_member :
0112     traits::query_static_constexpr_member<
0113       typename static_proxy<T>::type, context_t> {};
0114 
0115 #if defined(BOOST_ASIO_HAS_DEDUCED_STATIC_QUERY_TRAIT) \
0116   && defined(BOOST_ASIO_HAS_SFINAE_VARIABLE_TEMPLATES)
0117   template <typename T>
0118   static constexpr typename query_static_constexpr_member<T>::result_type
0119   static_query()
0120     noexcept(query_static_constexpr_member<T>::is_noexcept)
0121   {
0122     return query_static_constexpr_member<T>::value();
0123   }
0124 
0125   template <typename E, typename T = decltype(context_t::static_query<E>())>
0126   static constexpr const T static_query_v = context_t::static_query<E>();
0127 #endif // defined(BOOST_ASIO_HAS_DEDUCED_STATIC_QUERY_TRAIT)
0128        //   && defined(BOOST_ASIO_HAS_SFINAE_VARIABLE_TEMPLATES)
0129 };
0130 
0131 #if defined(BOOST_ASIO_HAS_DEDUCED_STATIC_QUERY_TRAIT) \
0132   && defined(BOOST_ASIO_HAS_SFINAE_VARIABLE_TEMPLATES)
0133 template <int I> template <typename E, typename T>
0134 const T context_t<I>::static_query_v;
0135 #endif // defined(BOOST_ASIO_HAS_DEDUCED_STATIC_QUERY_TRAIT)
0136        //   && defined(BOOST_ASIO_HAS_SFINAE_VARIABLE_TEMPLATES)
0137 
0138 } // namespace detail
0139 
0140 typedef detail::context_t<> context_t;
0141 
0142 BOOST_ASIO_INLINE_VARIABLE constexpr context_t context;
0143 
0144 } // namespace execution
0145 
0146 #if !defined(BOOST_ASIO_HAS_VARIABLE_TEMPLATES)
0147 
0148 template <typename T>
0149 struct is_applicable_property<T, execution::context_t>
0150   : integral_constant<bool, execution::is_executor<T>::value>
0151 {
0152 };
0153 
0154 #endif // !defined(BOOST_ASIO_HAS_VARIABLE_TEMPLATES)
0155 
0156 namespace traits {
0157 
0158 #if !defined(BOOST_ASIO_HAS_DEDUCED_STATIC_QUERY_TRAIT) \
0159   || !defined(BOOST_ASIO_HAS_SFINAE_VARIABLE_TEMPLATES)
0160 
0161 template <typename T>
0162 struct static_query<T, execution::context_t,
0163   enable_if_t<
0164     execution::detail::context_t<0>::
0165       query_static_constexpr_member<T>::is_valid
0166   >>
0167 {
0168   static constexpr bool is_valid = true;
0169   static constexpr bool is_noexcept = true;
0170 
0171   typedef typename execution::detail::context_t<0>::
0172     query_static_constexpr_member<T>::result_type result_type;
0173 
0174   static constexpr result_type value()
0175   {
0176     return execution::detail::context_t<0>::
0177       query_static_constexpr_member<T>::value();
0178   }
0179 };
0180 
0181 #endif // !defined(BOOST_ASIO_HAS_DEDUCED_STATIC_QUERY_TRAIT)
0182        //   || !defined(BOOST_ASIO_HAS_SFINAE_VARIABLE_TEMPLATES)
0183 
0184 } // namespace traits
0185 
0186 #endif // defined(GENERATING_DOCUMENTATION)
0187 
0188 } // namespace asio
0189 } // namespace boost
0190 
0191 #include <boost/asio/detail/pop_options.hpp>
0192 
0193 #endif // BOOST_ASIO_EXECUTION_CONTEXT2_HPP