// // execution/context.hpp // ~~~~~~~~~~~~~~~~~~~~~ // // Copyright (c) 2003-2024 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_CONTEXT2_HPP #define ASIO_EXECUTION_CONTEXT2_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/is_applicable_property.hpp" #include "asio/traits/query_static_constexpr_member.hpp" #include "asio/traits/static_query.hpp" #if defined(ASIO_HAS_STD_ANY) # include #endif // defined(ASIO_HAS_STD_ANY) #include "asio/detail/push_options.hpp" namespace asio { #if defined(GENERATING_DOCUMENTATION) namespace execution { /// A property that is used to obtain the execution context that is associated /// with an executor. struct context_t { /// The context_t property applies to executors. template static constexpr bool is_applicable_property_v = is_executor_v; /// The context_t property cannot be required. static constexpr bool is_requirable = false; /// The context_t property cannot be preferred. static constexpr bool is_preferable = false; /// The type returned by queries against an @c any_executor. typedef std::any polymorphic_query_result_type; }; /// A special value used for accessing the context_t property. constexpr context_t context; } // namespace execution #else // defined(GENERATING_DOCUMENTATION) namespace execution { namespace detail { template struct context_t { #if defined(ASIO_HAS_VARIABLE_TEMPLATES) template static constexpr bool is_applicable_property_v = is_executor::value; #endif // defined(ASIO_HAS_VARIABLE_TEMPLATES) static constexpr bool is_requirable = false; static constexpr bool is_preferable = false; #if defined(ASIO_HAS_STD_ANY) typedef std::any polymorphic_query_result_type; #endif // defined(ASIO_HAS_STD_ANY) constexpr context_t() { } template struct static_proxy { #if defined(ASIO_HAS_DEDUCED_QUERY_STATIC_CONSTEXPR_MEMBER_TRAIT) struct type { template static constexpr auto query(P&& p) noexcept( noexcept( conditional_t::query(static_cast(p)) ) ) -> decltype( conditional_t::query(static_cast(p)) ) { return T::query(static_cast(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, context_t> {}; #if defined(ASIO_HAS_DEDUCED_STATIC_QUERY_TRAIT) \ && defined(ASIO_HAS_SFINAE_VARIABLE_TEMPLATES) template static constexpr typename query_static_constexpr_member::result_type static_query() noexcept(query_static_constexpr_member::is_noexcept) { return query_static_constexpr_member::value(); } template ())> static constexpr const T static_query_v = context_t::static_query(); #endif // defined(ASIO_HAS_DEDUCED_STATIC_QUERY_TRAIT) // && defined(ASIO_HAS_SFINAE_VARIABLE_TEMPLATES) }; #if defined(ASIO_HAS_DEDUCED_STATIC_QUERY_TRAIT) \ && defined(ASIO_HAS_SFINAE_VARIABLE_TEMPLATES) template template const T context_t::static_query_v; #endif // defined(ASIO_HAS_DEDUCED_STATIC_QUERY_TRAIT) // && defined(ASIO_HAS_SFINAE_VARIABLE_TEMPLATES) } // namespace detail typedef detail::context_t<> context_t; constexpr context_t context; } // namespace execution #if !defined(ASIO_HAS_VARIABLE_TEMPLATES) template struct is_applicable_property : integral_constant::value> { }; #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 >> { static constexpr bool is_valid = true; static constexpr bool is_noexcept = true; typedef typename execution::detail::context_t<0>:: query_static_constexpr_member::result_type result_type; static constexpr result_type value() { return execution::detail::context_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_CONTEXT2_HPP