1
+ // src/Beman/Execution26/tests/exec-get-compl-sched.pass.cpp -*-C++-*-
2
+ // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
3
+
4
+ #include < Beman/Execution26/detail/get_completion_scheduler.hpp>
5
+ #include < Beman/Execution26/detail/forwarding_query.hpp>
6
+ #include < Beman/Execution26/detail/set_error.hpp>
7
+ #include < Beman/Execution26/detail/set_stopped.hpp>
8
+ #include < Beman/Execution26/detail/set_value.hpp>
9
+ #include < concepts>
10
+ #include < test/execution.hpp>
11
+
12
+ // ----------------------------------------------------------------------------
13
+
14
+ namespace
15
+ {
16
+ struct tag {};
17
+
18
+ template <typename Tag>
19
+ struct scheduler
20
+ {
21
+ int value{};
22
+ auto operator == (scheduler const &) const -> bool = default ;
23
+ };
24
+
25
+ struct env
26
+ {
27
+ int value{};
28
+ auto query (test_std::get_completion_scheduler_t <test_std::set_value_t > const &) const noexcept
29
+ {
30
+ return scheduler<test_std::set_value_t >{this ->value + 1 };
31
+ }
32
+ auto query (test_std::get_completion_scheduler_t <test_std::set_error_t > const &) const noexcept
33
+ {
34
+ return scheduler<test_std::set_error_t >{this ->value + 2 };
35
+ }
36
+ auto query (test_std::get_completion_scheduler_t <test_std::set_stopped_t > const &) const noexcept
37
+ {
38
+ return scheduler<test_std::set_stopped_t >{this ->value + 3 };
39
+ }
40
+ template <typename Tag>
41
+ auto query (test_std::get_completion_scheduler_t <Tag> const &) const noexcept
42
+ {
43
+ return scheduler<Tag>{this ->value };
44
+ }
45
+ };
46
+
47
+ template <bool Expect, typename Tag, typename Env>
48
+ auto test_tag (Env&& env) -> void
49
+ {
50
+ static_assert (Expect == requires{ test_std::get_completion_scheduler<Tag>(env); });
51
+ }
52
+ }
53
+
54
+ auto main () -> int
55
+ {
56
+ static_assert (std::same_as<test_std::get_completion_scheduler_t <test_std::set_error_t > const ,
57
+ decltype (test_std::get_completion_scheduler<test_std::set_error_t >)>);
58
+ static_assert (std::same_as<test_std::get_completion_scheduler_t <test_std::set_stopped_t > const ,
59
+ decltype (test_std::get_completion_scheduler<test_std::set_stopped_t >)>);
60
+ static_assert (std::same_as<test_std::get_completion_scheduler_t <test_std::set_value_t > const ,
61
+ decltype (test_std::get_completion_scheduler<test_std::set_value_t >)>);
62
+ static_assert (test_std::forwarding_query (test_std::get_completion_scheduler<test_std::set_error_t >));
63
+ static_assert (test_std::forwarding_query (test_std::get_completion_scheduler<test_std::set_stopped_t >));
64
+ static_assert (test_std::forwarding_query (test_std::get_completion_scheduler<test_std::set_value_t >));
65
+
66
+ env e{17 };
67
+ test_tag<true , test_std::set_error_t >(e);
68
+ test_tag<true , test_std::set_stopped_t >(e);
69
+ test_tag<true , test_std::set_value_t >(e);
70
+ test_tag<false , tag>(e);
71
+
72
+ static_assert (::std::same_as<
73
+ decltype (test_std::get_completion_scheduler<test_std::set_error_t >(e)),
74
+ scheduler<test_std::set_error_t >>);
75
+ static_assert (::std::same_as<
76
+ decltype (test_std::get_completion_scheduler<test_std::set_stopped_t >(e)),
77
+ scheduler<test_std::set_stopped_t >>);
78
+ static_assert (::std::same_as<
79
+ decltype (test_std::get_completion_scheduler<test_std::set_value_t >(e)),
80
+ scheduler<test_std::set_value_t >>);
81
+ assert (test_std::get_completion_scheduler<test_std::set_error_t >(e)
82
+ == scheduler<test_std::set_error_t >{19 });
83
+ assert (test_std::get_completion_scheduler<test_std::set_stopped_t >(e)
84
+ == scheduler<test_std::set_stopped_t >{20 });
85
+ assert (test_std::get_completion_scheduler<test_std::set_value_t >(e)
86
+ == scheduler<test_std::set_value_t >{18 });
87
+ }
0 commit comments