// // execution/context_as.hpp // ~~~~~~~~~~~~~~~~~~~~~~~~ // // Copyright (c) 2003-2020 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_CONTEXT_AS_HPP #define ASIO_EXECUTION_CONTEXT_AS_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/context.hpp" #include "asio/execution/executor.hpp" #include "asio/execution/scheduler.hpp" #include "asio/execution/sender.hpp" #include "asio/is_applicable_property.hpp" #include "asio/query.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 is used to obtain the execution context that is associated /// with an executor. template struct context_as_t { /// The context_as_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 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 T polymorphic_query_result_type; }; /// A special value used for accessing the context_as_t property. template constexpr context_as_t context_as; } // namespace execution #else // defined(GENERATING_DOCUMENTATION) namespace execution { template struct context_as_t { #if defined(ASIO_HAS_VARIABLE_TEMPLATES) template ASIO_STATIC_CONSTEXPR(bool, is_applicable_property_v = is_executor::value || is_sender::value || is_scheduler::value); #endif // defined(ASIO_HAS_VARIABLE_TEMPLATES) ASIO_STATIC_CONSTEXPR(bool, is_requirable = false); ASIO_STATIC_CONSTEXPR(bool, is_preferable = false); typedef T polymorphic_query_result_type; ASIO_CONSTEXPR context_as_t() { } ASIO_CONSTEXPR context_as_t(context_t) { } #if defined(ASIO_HAS_DEDUCED_STATIC_QUERY_TRAIT) \ && defined(ASIO_HAS_SFINAE_VARIABLE_TEMPLATES) template static ASIO_CONSTEXPR typename traits::query_static_constexpr_member::result_type static_query() ASIO_NOEXCEPT_IF(( traits::query_static_constexpr_member::is_noexcept)) { return traits::query_static_constexpr_member::value(); } template ())> static ASIO_CONSTEXPR const U static_query_v = context_as_t::static_query(); #endif // defined(ASIO_HAS_DEDUCED_STATIC_QUERY_TRAIT) // && defined(ASIO_HAS_SFINAE_VARIABLE_TEMPLATES) template friend ASIO_CONSTEXPR U query( const Executor& ex, const context_as_t&, typename enable_if< is_same::value && can_query::value >::type* = 0) #if !defined(__clang__) // Clang crashes if noexcept is used here. #if defined(ASIO_MSVC) // Visual C++ wants the type to be qualified. ASIO_NOEXCEPT_IF(( is_nothrow_query::value)) #else // defined(ASIO_MSVC) ASIO_NOEXCEPT_IF(( is_nothrow_query::value)) #endif // defined(ASIO_MSVC) #endif // !defined(__clang__) { return asio::query(ex, context); } }; #if defined(ASIO_HAS_DEDUCED_STATIC_QUERY_TRAIT) \ && defined(ASIO_HAS_SFINAE_VARIABLE_TEMPLATES) template template const U context_as_t::static_query_v; #endif // defined(ASIO_HAS_DEDUCED_STATIC_QUERY_TRAIT) // && defined(ASIO_HAS_SFINAE_VARIABLE_TEMPLATES) #if (defined(ASIO_HAS_VARIABLE_TEMPLATES) \ && defined(ASIO_HAS_CONSTEXPR)) \ || defined(GENERATING_DOCUMENTATION) template constexpr context_as_t context_as{}; #endif // (defined(ASIO_HAS_VARIABLE_TEMPLATES) // && defined(ASIO_HAS_CONSTEXPR)) // || defined(GENERATING_DOCUMENTATION) } // namespace execution #if !defined(ASIO_HAS_VARIABLE_TEMPLATES) template struct is_applicable_property > : integral_constant::value || execution::is_sender::value || execution::is_scheduler::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, typename enable_if< static_query::is_valid >::type> : static_query { }; #endif // !defined(ASIO_HAS_DEDUCED_STATIC_QUERY_TRAIT) // || !defined(ASIO_HAS_SFINAE_VARIABLE_TEMPLATES) #if !defined(ASIO_HAS_DEDUCED_QUERY_FREE_TRAIT) template struct query_free, typename enable_if< can_query::value >::type> { ASIO_STATIC_CONSTEXPR(bool, is_valid = true); ASIO_STATIC_CONSTEXPR(bool, is_noexcept = (is_nothrow_query::value)); typedef U result_type; }; #endif // !defined(ASIO_HAS_DEDUCED_QUERY_FREE_TRAIT) } // namespace traits #endif // defined(GENERATING_DOCUMENTATION) } // namespace asio #include "asio/detail/pop_options.hpp" #endif // ASIO_EXECUTION_CONTEXT_AS_HPP