Back to home page

EIC code displayed by LXR

 
 

    


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

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