From a13604cf8de3a1bcab0a23c70ec23790cdd4678a Mon Sep 17 00:00:00 2001 From: Christopher Kohlhoff Date: Mon, 18 May 2020 19:02:01 +1000 Subject: [PATCH] Add execution::context property. --- asio/include/Makefile.am | 1 + asio/include/asio.hpp | 1 + asio/include/asio/execution/context.hpp | 167 ++++++++++++++++++++++++ 3 files changed, 169 insertions(+) create mode 100644 asio/include/asio/execution/context.hpp diff --git a/asio/include/Makefile.am b/asio/include/Makefile.am index cd2b5764..afd6bf4d 100644 --- a/asio/include/Makefile.am +++ b/asio/include/Makefile.am @@ -295,6 +295,7 @@ nobase_include_HEADERS = \ asio/execution/blocking.hpp \ asio/execution/blocking_adaptation.hpp \ asio/execution/bulk_guarantee.hpp \ + asio/execution/context.hpp \ asio/execution/execute.hpp \ asio/execution/executor.hpp \ asio/execution/invocable_archetype.hpp \ diff --git a/asio/include/asio.hpp b/asio/include/asio.hpp index a238a09c..f1f36e84 100644 --- a/asio/include/asio.hpp +++ b/asio/include/asio.hpp @@ -57,6 +57,7 @@ #include "asio/execution/blocking.hpp" #include "asio/execution/blocking_adaptation.hpp" #include "asio/execution/bulk_guarantee.hpp" +#include "asio/execution/context.hpp" #include "asio/execution/execute.hpp" #include "asio/execution/executor.hpp" #include "asio/execution/invocable_archetype.hpp" diff --git a/asio/include/asio/execution/context.hpp b/asio/include/asio/execution/context.hpp new file mode 100644 index 00000000..183d28f0 --- /dev/null +++ b/asio/include/asio/execution/context.hpp @@ -0,0 +1,167 @@ +// +// execution/context.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_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" + +#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; +}; + +/// 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 + ASIO_STATIC_CONSTEXPR(bool, + is_applicable_property_v = is_executor::value); +#endif // defined(ASIO_HAS_VARIABLE_TEMPLATES) + + ASIO_STATIC_CONSTEXPR(bool, is_requirable = false); + ASIO_STATIC_CONSTEXPR(bool, is_preferable = false); + + ASIO_CONSTEXPR 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 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_CONSTEXPR) + static const context_t instance; +#endif // !defined(ASIO_HAS_CONSTEXPR) +}; + +#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) + +#if !defined(ASIO_HAS_CONSTEXPR) +template +const context_t context_t::instance; +#endif + +} // namespace detail + +typedef detail::context_t<> context_t; + +#if defined(ASIO_HAS_CONSTEXPR) || defined(GENERATING_DOCUMENTATION) +constexpr context_t context; +#else // defined(ASIO_HAS_CONSTEXPR) || defined(GENERATING_DOCUMENTATION) +namespace { static const context_t& context = context_t::instance; } +#endif + +} // namespace execution + +#if !defined(ASIO_HAS_VARIABLE_TEMPLATES) + +template +struct is_applicable_property + : execution::is_executor +{ +}; + +#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::is_valid + >::type> +{ + ASIO_STATIC_CONSTEXPR(bool, is_valid = true); + ASIO_STATIC_CONSTEXPR(bool, is_noexcept = true); + + typedef typename traits::query_static_constexpr_member::result_type result_type; + + static ASIO_CONSTEXPR result_type value() + { + return traits::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