From eba45e855ae85a00c361ca49a81d8c25c2aadffc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dietmar=20K=C3=BChl?= Date: Tue, 30 Jul 2024 23:40:27 +0100 Subject: [PATCH] added get_stop_token --- docs/TODO.json | 1 + docs/TODO.md | 2 +- docs/questions.md | 2 +- .../Execution26/detail/get_stop_token.hpp | 45 +++++++++++++ include/Beman/Execution26/execution.hpp | 2 + include/Beman/Execution26/stop_token.hpp | 1 + src/Beman/Execution26/tests/CMakeLists.txt | 1 + .../tests/exec-get-allocator.pass.cpp | 3 +- .../tests/exec-get-stop-token.pass.cpp | 63 +++++++++++++++++++ 9 files changed, 116 insertions(+), 4 deletions(-) create mode 100644 include/Beman/Execution26/detail/get_stop_token.hpp create mode 100644 src/Beman/Execution26/tests/exec-get-stop-token.pass.cpp diff --git a/docs/TODO.json b/docs/TODO.json index 9ab3b142..e3fa4eff 100644 --- a/docs/TODO.json +++ b/docs/TODO.json @@ -6,6 +6,7 @@ "execution.queryable.general]": { "code":true, "test":true, "doc":false, "comment":"nothing testable" }, "execution.forwarding_query": { "code":true, "test":true, "doc":false }, "execution.get_allocator": { "code":true, "test":true, "doc":false }, + "execution.get_stop_token": { "code":true, "test":true, "doc":false }, "execution.queryable.concepts": { "code":true, "test":true, "doc":false }, "execution.receivers": { "code":true, "test":true, "doc":true, "comment":"empty" }, "execution.senders": { "code":true, "test":true, "doc":true, "comment":"empty" }, diff --git a/docs/TODO.md b/docs/TODO.md index 3a6b8492..41cb6bf2 100644 --- a/docs/TODO.md +++ b/docs/TODO.md @@ -51,7 +51,7 @@ | [[execution.queries](https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2024/p2300r10.html#execution.queries)] | ✅ | ✅ | ✅ | empty | | [[execution.forwarding_query](https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2024/p2300r10.html#execution.forwarding_query)] | ✅ | ✅ | 🔴 | | | [[execution.get_allocator](https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2024/p2300r10.html#execution.get_allocator)] | ✅ | ✅ | 🔴 | | -| [[execution.get_stop_token](https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2024/p2300r10.html#execution.get_stop_token)] | 🔴 | 🔴 | 🔴 | | +| [[execution.get_stop_token](https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2024/p2300r10.html#execution.get_stop_token)] | ✅ | ✅ | 🔴 | | | [[execution.environment.get_env](https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2024/p2300r10.html#execution.environment.get_env)] | 🔴 | 🔴 | 🔴 | | | [[execution.get_domain](https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2024/p2300r10.html#execution.get_domain)] | 🔴 | 🔴 | 🔴 | | | [[execution.get_scheduler](https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2024/p2300r10.html#execution.get_scheduler)] | 🔴 | 🔴 | 🔴 | | diff --git a/docs/questions.md b/docs/questions.md index f52bab6b..86eaf434 100644 --- a/docs/questions.md +++ b/docs/questions.md @@ -14,4 +14,4 @@ likely observable. The "Mandates" should be "Precondition". - [exec.fwd.env] states "Mandates: ... is a core constant expression if `q` is a core constant expression": I don't know how to possibly - implement that. \ No newline at end of file + implement that. diff --git a/include/Beman/Execution26/detail/get_stop_token.hpp b/include/Beman/Execution26/detail/get_stop_token.hpp new file mode 100644 index 00000000..e182e488 --- /dev/null +++ b/include/Beman/Execution26/detail/get_stop_token.hpp @@ -0,0 +1,45 @@ +// include/Beman/Execution26/detail/get_stop_token.hpp -*-C++-*- +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + +#ifndef INCLUDED_BEMAN_EXECUTION26_DETAIL_GET_STOP_TOKEN +#define INCLUDED_BEMAN_EXECUTION26_DETAIL_GET_STOP_TOKEN + +#include +#include +#include +#include + +// ---------------------------------------------------------------------------- + +namespace Beman::Execution26 +{ + struct get_stop_token_t + { + template + requires requires(Object&& object, get_stop_token_t const& tag) + { + { ::std::as_const(object).query(tag) } noexcept -> ::Beman::Execution26::stoppable_token; + } + auto operator()(Object&& object) const noexcept + { + return ::std::as_const(object).query(*this); + } + + template + auto operator()(Object&&) const noexcept -> ::Beman::Execution26::never_stop_token + { + return {}; + } + + constexpr auto query(::Beman::Execution26::forwarding_query_t const&) const noexcept -> bool + { + return true; + } + }; + + inline constexpr get_stop_token_t get_stop_token{}; +} + +// ---------------------------------------------------------------------------- + +#endif diff --git a/include/Beman/Execution26/execution.hpp b/include/Beman/Execution26/execution.hpp index 0ff79db1..b183b776 100644 --- a/include/Beman/Execution26/execution.hpp +++ b/include/Beman/Execution26/execution.hpp @@ -8,6 +8,8 @@ #include #include +#include +#include #include #include diff --git a/include/Beman/Execution26/stop_token.hpp b/include/Beman/Execution26/stop_token.hpp index 6189266f..4e2ebf89 100644 --- a/include/Beman/Execution26/stop_token.hpp +++ b/include/Beman/Execution26/stop_token.hpp @@ -11,6 +11,7 @@ #include #include #include +#include #include // ---------------------------------------------------------------------------- diff --git a/src/Beman/Execution26/tests/CMakeLists.txt b/src/Beman/Execution26/tests/CMakeLists.txt index 18f407f5..e5307083 100644 --- a/src/Beman/Execution26/tests/CMakeLists.txt +++ b/src/Beman/Execution26/tests/CMakeLists.txt @@ -2,6 +2,7 @@ # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception list(APPEND execution_tests + exec-get-stop-token.pass exec-get-allocator.pass exec-fwd-env.pass exec-opstate.pass diff --git a/src/Beman/Execution26/tests/exec-get-allocator.pass.cpp b/src/Beman/Execution26/tests/exec-get-allocator.pass.cpp index c73203f1..36d627b6 100644 --- a/src/Beman/Execution26/tests/exec-get-allocator.pass.cpp +++ b/src/Beman/Execution26/tests/exec-get-allocator.pass.cpp @@ -1,7 +1,6 @@ -// src/Beman/Execution26/tests/exec.get.allocator.pass.cpp -*-C++-*- +// src/Beman/Execution26/tests/exec-get-allocator.pass.cpp -*-C++-*- // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -#include #include #include #include diff --git a/src/Beman/Execution26/tests/exec-get-stop-token.pass.cpp b/src/Beman/Execution26/tests/exec-get-stop-token.pass.cpp new file mode 100644 index 00000000..1b295c61 --- /dev/null +++ b/src/Beman/Execution26/tests/exec-get-stop-token.pass.cpp @@ -0,0 +1,63 @@ +// src/Beman/Execution26/tests/exec-get-stop-token.pass.cpp -*-C++-*- +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + +#include +#include +#include +#include + +// ---------------------------------------------------------------------------- + +namespace +{ + struct non_stop_token {}; + struct stop_token + { + template + struct callback_type {}; + auto stop_requested() const noexcept -> bool { return {}; } + auto stop_possible() const noexcept -> bool { return {}; } + auto operator== (stop_token const&) const noexcept -> bool = default; + }; + + struct no_get_stop_token {}; + + struct non_const_get_stop_token + { + auto query(test_std::get_stop_token_t const&) noexcept -> stop_token { return {}; } + }; + template + struct has_get_stop_token + { + auto query(test_std::get_stop_token_t const&) const noexcept(Noexcept) -> stop_token { return {}; } + }; + + struct inconsistent_get_stop_token + { + auto query(test_std::get_stop_token_t const&) const noexcept -> stop_token { return {}; } + auto query(test_std::get_stop_token_t const&) noexcept -> non_stop_token { return {}; } + }; + + + template + auto test_get_stop_token(Object&& object) + { + static_assert(requires { test_std::get_stop_token(object); }); + static_assert(std::same_as); + } +} + +auto main() -> int +{ + static_assert(std::same_as); + static_assert(test_std::forwarding_query(test_std::get_stop_token)); + + test_get_stop_token(no_get_stop_token()); + test_get_stop_token(has_get_stop_token()); + test_get_stop_token(has_get_stop_token()); + test_get_stop_token(non_const_get_stop_token()); + test_get_stop_token(inconsistent_get_stop_token()); + + static_assert(test_std::stoppable_token); +} \ No newline at end of file