Skip to content

Commit eba45e8

Browse files
committed
added get_stop_token
1 parent 605fb95 commit eba45e8

File tree

9 files changed

+116
-4
lines changed

9 files changed

+116
-4
lines changed

docs/TODO.json

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
"execution.queryable.general]": { "code":true, "test":true, "doc":false, "comment":"nothing testable" },
77
"execution.forwarding_query": { "code":true, "test":true, "doc":false },
88
"execution.get_allocator": { "code":true, "test":true, "doc":false },
9+
"execution.get_stop_token": { "code":true, "test":true, "doc":false },
910
"execution.queryable.concepts": { "code":true, "test":true, "doc":false },
1011
"execution.receivers": { "code":true, "test":true, "doc":true, "comment":"empty" },
1112
"execution.senders": { "code":true, "test":true, "doc":true, "comment":"empty" },

docs/TODO.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151
| [[execution.queries](https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2024/p2300r10.html#execution.queries)] | ✅ | ✅ | ✅ | empty |
5252
| [[execution.forwarding_query](https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2024/p2300r10.html#execution.forwarding_query)] | ✅ | ✅ | 🔴 | |
5353
| [[execution.get_allocator](https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2024/p2300r10.html#execution.get_allocator)] | ✅ | ✅ | 🔴 | |
54-
| [[execution.get_stop_token](https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2024/p2300r10.html#execution.get_stop_token)] | 🔴 | 🔴 | 🔴 | |
54+
| [[execution.get_stop_token](https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2024/p2300r10.html#execution.get_stop_token)] | ✅ | ✅ | 🔴 | |
5555
| [[execution.environment.get_env](https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2024/p2300r10.html#execution.environment.get_env)] | 🔴 | 🔴 | 🔴 | |
5656
| [[execution.get_domain](https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2024/p2300r10.html#execution.get_domain)] | 🔴 | 🔴 | 🔴 | |
5757
| [[execution.get_scheduler](https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2024/p2300r10.html#execution.get_scheduler)] | 🔴 | 🔴 | 🔴 | |

docs/questions.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,4 @@ likely observable.
1414
The "Mandates" should be "Precondition".
1515
- [exec.fwd.env] states "Mandates: ... is a core constant expression if
1616
`q` is a core constant expression": I don't know how to possibly
17-
implement that.
17+
implement that.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
// include/Beman/Execution26/detail/get_stop_token.hpp -*-C++-*-
2+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
3+
4+
#ifndef INCLUDED_BEMAN_EXECUTION26_DETAIL_GET_STOP_TOKEN
5+
#define INCLUDED_BEMAN_EXECUTION26_DETAIL_GET_STOP_TOKEN
6+
7+
#include <Beman/Execution26/detail/forwarding_query.hpp>
8+
#include <Beman/Execution26/detail/never_stop_token.hpp>
9+
#include <Beman/Execution26/detail/stoppable_token.hpp>
10+
#include <utility>
11+
12+
// ----------------------------------------------------------------------------
13+
14+
namespace Beman::Execution26
15+
{
16+
struct get_stop_token_t
17+
{
18+
template <typename Object>
19+
requires requires(Object&& object, get_stop_token_t const& tag)
20+
{
21+
{ ::std::as_const(object).query(tag) } noexcept -> ::Beman::Execution26::stoppable_token;
22+
}
23+
auto operator()(Object&& object) const noexcept
24+
{
25+
return ::std::as_const(object).query(*this);
26+
}
27+
28+
template <typename Object>
29+
auto operator()(Object&&) const noexcept -> ::Beman::Execution26::never_stop_token
30+
{
31+
return {};
32+
}
33+
34+
constexpr auto query(::Beman::Execution26::forwarding_query_t const&) const noexcept -> bool
35+
{
36+
return true;
37+
}
38+
};
39+
40+
inline constexpr get_stop_token_t get_stop_token{};
41+
}
42+
43+
// ----------------------------------------------------------------------------
44+
45+
#endif

include/Beman/Execution26/execution.hpp

+2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88

99
#include <Beman/Execution26/detail/queryable.hpp>
1010
#include <Beman/Execution26/detail/forwarding_query.hpp>
11+
#include <Beman/Execution26/detail/get_allocator.hpp>
12+
#include <Beman/Execution26/detail/get_stop_token.hpp>
1113
#include <Beman/Execution26/detail/get_env.hpp>
1214

1315
#include <Beman/Execution26/detail/completion_signature.hpp>

include/Beman/Execution26/stop_token.hpp

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include <Beman/Execution26/detail/stop_callback_for_t.hpp>
1212
#include <Beman/Execution26/detail/stop_source.hpp>
1313
#include <Beman/Execution26/detail/stoppable_source.hpp>
14+
#include <Beman/Execution26/detail/stoppable_token.hpp>
1415
#include <Beman/Execution26/detail/unstoppable_token.hpp>
1516

1617
// ----------------------------------------------------------------------------

src/Beman/Execution26/tests/CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
33

44
list(APPEND execution_tests
5+
exec-get-stop-token.pass
56
exec-get-allocator.pass
67
exec-fwd-env.pass
78
exec-opstate.pass

src/Beman/Execution26/tests/exec-get-allocator.pass.cpp

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
// src/Beman/Execution26/tests/exec.get.allocator.pass.cpp -*-C++-*-
1+
// src/Beman/Execution26/tests/exec-get-allocator.pass.cpp -*-C++-*-
22
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
33

4-
#include <Beman/Execution26/detail/get_allocator.hpp>
54
#include <Beman/Execution26/execution.hpp>
65
#include <test/execution.hpp>
76
#include <concepts>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
// src/Beman/Execution26/tests/exec-get-stop-token.pass.cpp -*-C++-*-
2+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
3+
4+
#include <Beman/Execution26/execution.hpp>
5+
#include <Beman/Execution26/stop_token.hpp>
6+
#include <test/execution.hpp>
7+
#include <concepts>
8+
9+
// ----------------------------------------------------------------------------
10+
11+
namespace
12+
{
13+
struct non_stop_token {};
14+
struct stop_token
15+
{
16+
template <typename CB>
17+
struct callback_type {};
18+
auto stop_requested() const noexcept -> bool { return {}; }
19+
auto stop_possible() const noexcept -> bool { return {}; }
20+
auto operator== (stop_token const&) const noexcept -> bool = default;
21+
};
22+
23+
struct no_get_stop_token {};
24+
25+
struct non_const_get_stop_token
26+
{
27+
auto query(test_std::get_stop_token_t const&) noexcept -> stop_token { return {}; }
28+
};
29+
template <bool Noexcept>
30+
struct has_get_stop_token
31+
{
32+
auto query(test_std::get_stop_token_t const&) const noexcept(Noexcept) -> stop_token { return {}; }
33+
};
34+
35+
struct inconsistent_get_stop_token
36+
{
37+
auto query(test_std::get_stop_token_t const&) const noexcept -> stop_token { return {}; }
38+
auto query(test_std::get_stop_token_t const&) noexcept -> non_stop_token { return {}; }
39+
};
40+
41+
42+
template <typename Result, typename Object>
43+
auto test_get_stop_token(Object&& object)
44+
{
45+
static_assert(requires { test_std::get_stop_token(object); });
46+
static_assert(std::same_as<Result, decltype(test_std::get_stop_token(object))>);
47+
}
48+
}
49+
50+
auto main() -> int
51+
{
52+
static_assert(std::same_as<test_std::get_stop_token_t const,
53+
decltype(test_std::get_stop_token)>);
54+
static_assert(test_std::forwarding_query(test_std::get_stop_token));
55+
56+
test_get_stop_token<test_std::never_stop_token>(no_get_stop_token());
57+
test_get_stop_token<stop_token>(has_get_stop_token<true>());
58+
test_get_stop_token<test_std::never_stop_token>(has_get_stop_token<false>());
59+
test_get_stop_token<test_std::never_stop_token>(non_const_get_stop_token());
60+
test_get_stop_token<stop_token>(inconsistent_get_stop_token());
61+
62+
static_assert(test_std::stoppable_token<stop_token>);
63+
}

0 commit comments

Comments
 (0)