55#include < optional>
66#include < system_error>
77#include < test/execution.hpp>
8+ #include < test/optional_sender.hpp>
89#ifdef BEMAN_HAS_MODULES
910import beman.execution;
1011import beman.execution.detail;
@@ -18,41 +19,6 @@ import beman.execution.detail;
1819
1920// ----------------------------------------------------------------------------
2021namespace {
21- template <typename T>
22- struct optional_sender {
23- using sender_concept = test_std::sender_t ;
24- using completion_signatures = test_std::completion_signatures<test_std::set_value_t (T), test_std::set_stopped_t ()>;
25-
26- optional_sender () = default;
27-
28- explicit optional_sender (T value) noexcept : opt(value) {}
29-
30- template <typename , typename ...>
31- static consteval auto get_completion_signatures () noexcept -> completion_signatures {
32- return {};
33- }
34-
35- template <test_std::receiver_of<completion_signatures> Rcvr>
36- auto connect (Rcvr rcvr) && noexcept -> auto {
37- struct state {
38- using operation_state_concept = test_std::operation_state_t ;
39- auto start () & noexcept -> void {
40- test::use_type<operation_state_concept>(); // make -Werror=unused-local-typedefs happy
41- if (opt_) {
42- test_std::set_value (std::move (rcvr_), *opt_);
43- } else {
44- test_std::set_stopped (std::move (rcvr_));
45- }
46- }
47-
48- Rcvr rcvr_;
49- std::optional<T> opt_;
50- };
51- return state{rcvr, std::move (opt)};
52- }
53-
54- std::optional<T> opt;
55- };
5622
5723auto test_stopped_as_error_signatures () -> void {
5824 test_std::sender auto sndr1 = test_std::just (42 ) | test_std::stopped_as_error (-1 );
@@ -61,7 +27,7 @@ auto test_stopped_as_error_signatures() -> void {
6127 auto [i] = test_std::sync_wait (std::move (sndr1)).value ();
6228 ASSERT (i == 42 );
6329
64- test_std::sender auto sndr2 = test_std::stopped_as_error (optional_sender<int >{}, 114514 );
30+ test_std::sender auto sndr2 = test_std::stopped_as_error (test:: optional_sender<int >{}, 114514 );
6531 using sigs_of_sndr2 = test_std::completion_signatures_of_t <decltype (sndr2), test_detail::sync_wait_env>;
6632 static_assert (
6733 std::same_as<sigs_of_sndr2,
@@ -75,8 +41,8 @@ auto test_stopped_as_error_signatures() -> void {
7541
7642auto test_stopped_as_std_error_code () -> void {
7743 try {
78- auto snd =
79- test_std::stopped_as_error (optional_sender< int >{}, std::make_error_code (std::errc::operation_canceled));
44+ auto snd = test_std::stopped_as_error (test::optional_sender< int >{},
45+ std::make_error_code (std::errc::operation_canceled));
8046 test_std::sync_wait (std::move (snd));
8147 } catch (const std::system_error& e) {
8248 ASSERT (e.code () == std::errc::operation_canceled);
0 commit comments