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