Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added get_stop_token #3

Merged
merged 1 commit into from
Jul 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/TODO.json
Original file line number Diff line number Diff line change
Expand Up @@ -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" },
Expand Down
2 changes: 1 addition & 1 deletion docs/TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)] | 🔴 | 🔴 | 🔴 | |
Expand Down
2 changes: 1 addition & 1 deletion docs/questions.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
implement that.
45 changes: 45 additions & 0 deletions include/Beman/Execution26/detail/get_stop_token.hpp
Original file line number Diff line number Diff line change
@@ -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 <Beman/Execution26/detail/forwarding_query.hpp>
#include <Beman/Execution26/detail/never_stop_token.hpp>
#include <Beman/Execution26/detail/stoppable_token.hpp>
#include <utility>

// ----------------------------------------------------------------------------

namespace Beman::Execution26
{
struct get_stop_token_t
{
template <typename Object>
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 <typename Object>
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
2 changes: 2 additions & 0 deletions include/Beman/Execution26/execution.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

#include <Beman/Execution26/detail/queryable.hpp>
#include <Beman/Execution26/detail/forwarding_query.hpp>
#include <Beman/Execution26/detail/get_allocator.hpp>
#include <Beman/Execution26/detail/get_stop_token.hpp>
#include <Beman/Execution26/detail/get_env.hpp>

#include <Beman/Execution26/detail/completion_signature.hpp>
Expand Down
1 change: 1 addition & 0 deletions include/Beman/Execution26/stop_token.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include <Beman/Execution26/detail/stop_callback_for_t.hpp>
#include <Beman/Execution26/detail/stop_source.hpp>
#include <Beman/Execution26/detail/stoppable_source.hpp>
#include <Beman/Execution26/detail/stoppable_token.hpp>
#include <Beman/Execution26/detail/unstoppable_token.hpp>

// ----------------------------------------------------------------------------
Expand Down
1 change: 1 addition & 0 deletions src/Beman/Execution26/tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 1 addition & 2 deletions src/Beman/Execution26/tests/exec-get-allocator.pass.cpp
Original file line number Diff line number Diff line change
@@ -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 <Beman/Execution26/detail/get_allocator.hpp>
#include <Beman/Execution26/execution.hpp>
#include <test/execution.hpp>
#include <concepts>
Expand Down
63 changes: 63 additions & 0 deletions src/Beman/Execution26/tests/exec-get-stop-token.pass.cpp
Original file line number Diff line number Diff line change
@@ -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 <Beman/Execution26/execution.hpp>
#include <Beman/Execution26/stop_token.hpp>
#include <test/execution.hpp>
#include <concepts>

// ----------------------------------------------------------------------------

namespace
{
struct non_stop_token {};
struct stop_token
{
template <typename CB>
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 <bool Noexcept>
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 <typename Result, typename Object>
auto test_get_stop_token(Object&& object)
{
static_assert(requires { test_std::get_stop_token(object); });
static_assert(std::same_as<Result, decltype(test_std::get_stop_token(object))>);
}
}

auto main() -> int
{
static_assert(std::same_as<test_std::get_stop_token_t const,
decltype(test_std::get_stop_token)>);
static_assert(test_std::forwarding_query(test_std::get_stop_token));

test_get_stop_token<test_std::never_stop_token>(no_get_stop_token());
test_get_stop_token<stop_token>(has_get_stop_token<true>());
test_get_stop_token<test_std::never_stop_token>(has_get_stop_token<false>());
test_get_stop_token<test_std::never_stop_token>(non_const_get_stop_token());
test_get_stop_token<stop_token>(inconsistent_get_stop_token());

static_assert(test_std::stoppable_token<stop_token>);
}