Skip to content

Commit a38e8ce

Browse files
committed
fixed some types of when_all
1 parent 2ca3cb2 commit a38e8ce

3 files changed

Lines changed: 38 additions & 4 deletions

File tree

include/beman/execution/detail/when_all.hpp

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import std;
1616
#include <type_traits>
1717
#include <utility>
1818
#include <variant>
19+
#include <iostream> //-dk:TODO remove
1920
#endif
2021
#ifdef BEMAN_HAS_MODULES
2122
import beman.execution.detail.basic_sender;
@@ -47,6 +48,7 @@ import beman.execution.detail.meta.to;
4748
import beman.execution.detail.meta.transform;
4849
import beman.execution.detail.meta.unique;
4950
import beman.execution.detail.on_stop_request;
51+
import beman.execution.detail.prop;
5052
import beman.execution.detail.sender;
5153
import beman.execution.detail.sender_in;
5254
import beman.execution.detail.sends_stopped;
@@ -85,6 +87,7 @@ import beman.execution.detail.value_types_of_t;
8587
#include <beman/execution/detail/meta_transform.hpp>
8688
#include <beman/execution/detail/meta_unique.hpp>
8789
#include <beman/execution/detail/on_stop_request.hpp>
90+
#include <beman/execution/detail/prop.hpp>
8891
#include <beman/execution/detail/sender.hpp>
8992
#include <beman/execution/detail/sender_in.hpp>
9093
#include <beman/execution/detail/sends_stopped.hpp>
@@ -117,13 +120,20 @@ concept valid_when_all_sender = ::beman::execution::dependent_sender<Sender> ||
117120
inline constexpr auto make_when_all_env = [](const ::beman::execution::inplace_stop_source& stop_src,
118121
const auto& env) noexcept {
119122
return ::beman::execution::detail::join_env(
120-
::beman::execution::detail::make_env(::beman::execution::get_stop_token, stop_src.get_token()), env);
123+
::beman::execution::env{::beman::execution::prop{::beman::execution::get_stop_token, stop_src.get_token()}},
124+
env);
121125
};
122126

123127
template <typename Env>
124128
using when_all_env =
125129
decltype(make_when_all_env(::std::declval<::beman::execution::inplace_stop_source>(), ::std::declval<Env>()));
126130

131+
static_assert(std::same_as<::beman::execution::never_stop_token,
132+
decltype(::beman::execution::get_stop_token(::std::declval<::beman::execution::env<>>()))>);
133+
static_assert(std::same_as<::beman::execution::inplace_stop_token,
134+
decltype(::beman::execution::get_stop_token(
135+
::std::declval<when_all_env<::beman::execution::env<>>>()))>);
136+
127137
struct when_all_t {
128138
template <::beman::execution::sender... Sender>
129139
requires(0u != sizeof...(Sender)) && (... && beman::execution::detail::valid_when_all_sender<Sender>) &&
@@ -188,6 +198,7 @@ struct when_all_t {
188198
struct get_env_impl {
189199
template <typename State, typename Receiver>
190200
auto operator()(auto&&, State& state, const Receiver& receiver) const noexcept {
201+
std::cout << "when_all::get_env()\n";
191202
return make_when_all_env(state.stop_src, ::beman::execution::get_env(receiver));
192203
}
193204
};
@@ -202,7 +213,7 @@ struct when_all_t {
202213
template <typename Receiver, typename... Sender>
203214
struct state_type {
204215
struct nonesuch {};
205-
using env_t = ::beman::execution::env_of_t<Receiver>;
216+
using env_t = when_all_env<::beman::execution::env_of_t<Receiver>>;
206217
using copy_fail = ::std::conditional_t<
207218
(... && ::beman::execution::value_types_of_t<Sender,
208219
env_t,
@@ -291,7 +302,7 @@ struct when_all_t {
291302

292303
template <typename Receiver>
293304
struct make_state {
294-
template <::beman::execution::sender_in<::beman::execution::env_of_t<Receiver>>... Sender>
305+
template <::beman::execution::sender_in<when_all_env<::beman::execution::env_of_t<Receiver>>>... Sender>
295306
auto operator()(auto, auto, Sender&&...) const {
296307
return state_type<Receiver, Sender...>{};
297308
}

tests/beman/execution/exec-read-env.test.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,15 @@ import beman.execution;
99
#include <beman/execution/detail/read_env.hpp>
1010
#include <beman/execution/detail/common.hpp>
1111
#include <beman/execution/detail/get_domain.hpp>
12+
#include <beman/execution/detail/join_env.hpp>
1213
#include <beman/execution/detail/sender.hpp>
1314
#include <beman/execution/detail/sender_in.hpp>
1415
#include <beman/execution/detail/receiver.hpp>
1516
#include <beman/execution/detail/connect.hpp>
1617
#include <beman/execution/detail/start.hpp>
1718
#include <beman/execution/detail/get_stop_token.hpp>
19+
#include <beman/execution/detail/sync_wait.hpp>
20+
#include <beman/execution/detail/when_all.hpp>
1821
#endif
1922

2023
// ----------------------------------------------------------------------------
@@ -74,7 +77,24 @@ auto test_read_env_completions() -> void {
7477
auto r{test_std::read_env(test_std::get_stop_token)};
7578
test::check_type<test_std::completion_signatures<test_std::set_value_t(test_std::never_stop_token)>>(
7679
test_std::get_completion_signatures<decltype(r), test_std::env<>>());
80+
test::check_type<test_std::completion_signatures<test_std::set_value_t(test_std::never_stop_token)>>(
81+
test_std::get_completion_signatures<decltype(r), decltype(test_std::env{})>());
82+
test::check_type<test_std::completion_signatures<test_std::set_value_t(test_std::inplace_stop_token)>>(
83+
test_std::get_completion_signatures<decltype(r),
84+
decltype(test_std::env{
85+
test_std::prop{test_std::get_stop_token,
86+
std::declval<test_std::inplace_stop_token>()}})>());
87+
test::check_type<test_std::completion_signatures<test_std::set_value_t(test_std::inplace_stop_token)>>(
88+
test_std::get_completion_signatures<
89+
decltype(r),
90+
decltype(test_detail::join_env(
91+
test_std::env{test_std::prop{test_std::get_stop_token, std::declval<test_std::inplace_stop_token>()}},
92+
test_std::env{
93+
test_std::prop{test_std::get_stop_token, std::declval<test_std::never_stop_token>()}}))>());
7794
test::use(r);
95+
96+
test_std::sync_wait(test_std::read_env(test_std::get_stop_token));
97+
test_std::sync_wait(test_std::when_all(test_std::read_env(test_std::get_scheduler)));
7898
}
7999
} // namespace
80100

tests/beman/execution/exec-when-all.test.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,10 @@ auto test_when_all() -> void {
234234
await_cancel(),
235235
add_value{test_std::just_stopped()},
236236
test_std::just(true, 3.5));
237+
238+
test_std::sync_wait(test_std::read_env(test_std::get_stop_token));
239+
test_std::sync_wait(
240+
test_std::when_all(test_std::read_env(test_std::get_stop_token) | test_std::then([](auto&&) {})));
237241
}
238242

239243
auto test_when_all_with_variant() -> void {
@@ -265,7 +269,6 @@ TEST(exec_when_all) {
265269
static_assert(std::same_as<const test_std::when_all_with_variant_t, decltype(test_std::when_all_with_variant)>);
266270

267271
try {
268-
269272
test_when_all();
270273
test_when_all_with_variant();
271274
} catch (...) {

0 commit comments

Comments
 (0)