Skip to content

Commit

Permalink
Update when_all completion_signatures to match spec (NVIDIA#676)
Browse files Browse the repository at this point in the history
* Update when_all completion_signatures to match spec

The spec transforms types as std::decay_t<T>&&. Previously types from
children were sent unchanged.

* simplify metaprogramming

Co-authored-by: Eric Niebler <[email protected]>
  • Loading branch information
msimberg and ericniebler authored Nov 7, 2022
1 parent 5424a05 commit d43de31
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 18 deletions.
5 changes: 4 additions & 1 deletion include/stdexec/execution.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4638,14 +4638,17 @@ namespace stdexec {
_Env,
completion_signatures<>,
__swallow_values>...>;
template <class _T>
using __decay_rvalue_ref = decay_t<_T>&&;
using __values =
__minvoke<
__concat<__qf<set_value_t>>,
__value_types_of_t<
_Senders,
_Env,
__q<__types>,
__transform<__q<__decay_rvalue_ref>, __q<__types>>,
__single_or<__types<>>>...>;

using __t =
__if_c<
(__sends<set_value_t, _Senders, _Env> &&...),
Expand Down
42 changes: 25 additions & 17 deletions test/stdexec/algos/adaptors/test_when_all.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -222,29 +222,37 @@ TEST_CASE("when_all cancels remaining children if cancel is detected", "[adaptor
CHECK(cancelled);
}

TEST_CASE("when_all has the values_type based on the children", "[adaptors][when_all]") {
check_val_types<type_array<type_array<int>>>(ex::when_all(ex::just(13)));
check_val_types<type_array<type_array<double>>>(ex::when_all(ex::just(3.14)));
check_val_types<type_array<type_array<int, double>>>(ex::when_all(ex::just(3, 0.14)));
TEST_CASE("when_all has the values_type based on the children, decayed and as rvalue references", "[adaptors][when_all]") {
check_val_types<type_array<type_array<int&&>>>(ex::when_all(ex::just(13)));
check_val_types<type_array<type_array<double&&>>>(ex::when_all(ex::just(3.14)));
check_val_types<type_array<type_array<int&&, double&&>>>(ex::when_all(ex::just(3, 0.14)));

check_val_types<type_array<type_array<>>>(ex::when_all(ex::just()));

check_val_types<type_array<type_array<int, double>>>(ex::when_all(ex::just(3), ex::just(0.14)));
check_val_types<type_array<type_array<int, double, int, double>>>( //
ex::when_all( //
ex::just(3), //
ex::just(0.14), //
ex::just(1, 0.4142) //
) //
check_val_types<type_array<type_array<int&&, double&&>>>(ex::when_all(ex::just(3),
ex::just(0.14))); check_val_types<type_array<type_array<int&&, double&&, int&&, double&&>>>( //
ex::when_all( //
ex::just(3), //
ex::just(0.14), //
ex::just(1, 0.4142) //
) //
);

// if one child returns void, then the value is simply missing
check_val_types<type_array<type_array<int, double>>>( //
ex::when_all( //
ex::just(3), //
ex::just(), //
ex::just(0.14) //
) //
check_val_types<type_array<type_array<int&&, double&&>>>( //
ex::when_all( //
ex::just(3), //
ex::just(), //
ex::just(0.14) //
) //
);

// if children send references, they get decayed
check_val_types<type_array<type_array<int&&, double&&>>>( //
ex::when_all( //
ex::split(ex::just(3)), //
ex::split(ex::just(0.14)) //
) //
);
}

Expand Down

0 comments on commit d43de31

Please sign in to comment.