// // execution/context_as.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 BOOST_ASIO_EXECUTION_CONTEXT_AS_HPP #define BOOST_ASIO_EXECUTION_CONTEXT_AS_HPP #if defined(_MSC_VER) && (_MSC_VER >= 1200) # pragma once #endif // defined(_MSC_VER) && (_MSC_VER >= 1200) #include #include #include #include #include #include #include #include #include namespace boost { 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. 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 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(BOOST_ASIO_HAS_VARIABLE_TEMPLATES) template static constexpr bool is_applicable_property_v = is_executor::value; #endif // defined(BOOST_ASIO_HAS_VARIABLE_TEMPLATES) static constexpr bool is_requirable = false; static constexpr bool is_preferable = false; typedef T polymorphic_query_result_type; constexpr context_as_t() { } constexpr context_as_t(context_t) { } #if defined(BOOST_ASIO_HAS_DEDUCED_STATIC_QUERY_TRAIT) \ && defined(BOOST_ASIO_HAS_SFINAE_VARIABLE_TEMPLATES) template static constexpr typename context_t::query_static_constexpr_member::result_type static_query() noexcept(context_t::query_static_constexpr_member::is_noexcept) { return context_t::query_static_constexpr_member::value(); } template ())> static constexpr const U static_query_v = context_as_t::static_query(); #endif // defined(BOOST_ASIO_HAS_DEDUCED_STATIC_QUERY_TRAIT) // && defined(BOOST_ASIO_HAS_SFINAE_VARIABLE_TEMPLATES) template friend constexpr U query( const Executor& ex, const context_as_t&, enable_if_t< is_same::value >* = 0, enable_if_t< can_query::value >* = 0) #if !defined(__clang__) // Clang crashes if noexcept is used here. #if defined(BOOST_ASIO_MSVC) // Visual C++ wants the type to be qualified. noexcept(is_nothrow_query::value) #else // defined(BOOST_ASIO_MSVC) noexcept(is_nothrow_query::value) #endif // defined(BOOST_ASIO_MSVC) #endif // !defined(__clang__) { return boost::asio::query(ex, context); } }; #if defined(BOOST_ASIO_HAS_DEDUCED_STATIC_QUERY_TRAIT) \ && defined(BOOST_ASIO_HAS_SFINAE_VARIABLE_TEMPLATES) template template const U context_as_t::static_query_v; #endif // defined(BOOST_ASIO_HAS_DEDUCED_STATIC_QUERY_TRAIT) // && defined(BOOST_ASIO_HAS_SFINAE_VARIABLE_TEMPLATES) #if defined(BOOST_ASIO_HAS_VARIABLE_TEMPLATES) \ || defined(GENERATING_DOCUMENTATION) template constexpr context_as_t context_as{}; #endif // defined(BOOST_ASIO_HAS_VARIABLE_TEMPLATES) // || defined(GENERATING_DOCUMENTATION) } // namespace execution #if !defined(BOOST_ASIO_HAS_VARIABLE_TEMPLATES) template struct is_applicable_property> : integral_constant::value> { }; #endif // !defined(BOOST_ASIO_HAS_VARIABLE_TEMPLATES) namespace traits { #if !defined(BOOST_ASIO_HAS_DEDUCED_STATIC_QUERY_TRAIT) \ || !defined(BOOST_ASIO_HAS_SFINAE_VARIABLE_TEMPLATES) template struct static_query, enable_if_t< static_query::is_valid >> : static_query { }; #endif // !defined(BOOST_ASIO_HAS_DEDUCED_STATIC_QUERY_TRAIT) // || !defined(BOOST_ASIO_HAS_SFINAE_VARIABLE_TEMPLATES) #if !defined(BOOST_ASIO_HAS_DEDUCED_QUERY_FREE_TRAIT) template struct query_free, enable_if_t< can_query::value >> { static constexpr bool is_valid = true; static constexpr bool is_noexcept = is_nothrow_query::value; typedef U result_type; }; #endif // !defined(BOOST_ASIO_HAS_DEDUCED_QUERY_FREE_TRAIT) } // namespace traits #endif // defined(GENERATING_DOCUMENTATION) } // namespace asio } // namespace boost #include #endif // BOOST_ASIO_EXECUTION_CONTEXT_AS_HPP