Skip to content

Commit 2fd7edb

Browse files
authored
Merge pull request #2002 from ericniebler/fix-into-variant-variant-initialization
be explicit in `into_variant` about which variant alternative is being initialized
2 parents add8d34 + f28da1c commit 2fd7edb

File tree

3 files changed

+24
-5
lines changed

3 files changed

+24
-5
lines changed

include/stdexec/__detail/__into_variant.hpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,9 @@ namespace STDEXEC
8383
STDEXEC_TRY
8484
{
8585
STDEXEC::set_value(static_cast<_State&&>(__state).__rcvr_,
86-
__variant_t{
87-
std::tuple<_Args&&...>{static_cast<_Args&&>(__args)...}});
86+
__variant_t{std::in_place_type<__decayed_std_tuple<_Args...>>,
87+
std::tuple<_Args&&...>{
88+
static_cast<_Args&&>(__args)...}});
8889
}
8990
STDEXEC_CATCH_ALL
9091
{

include/stdexec/__detail/__when_all.hpp

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,16 @@ namespace STDEXEC
5656

5757
struct when_all_with_variant_t
5858
{
59+
private:
60+
static constexpr auto __mk_transform_fn() noexcept
61+
{
62+
return []<class... _Child>(__ignore, __ignore, _Child&&... __child)
63+
{
64+
return when_all(into_variant(static_cast<_Child&&>(__child))...);
65+
};
66+
}
67+
68+
public:
5969
template <sender... _Senders>
6070
constexpr auto operator()(_Senders&&... __sndrs) const -> __well_formed_sender auto
6171
{
@@ -66,9 +76,7 @@ namespace STDEXEC
6676
static constexpr auto transform_sender(set_value_t, _Sender&& __sndr, __ignore)
6777
{
6878
// transform when_all_with_variant(sndrs...) into when_all(into_variant(sndrs)...).
69-
return __apply([&]<class... _Child>(__ignore, __ignore, _Child&&... __child)
70-
{ return when_all(into_variant(static_cast<_Child&&>(__child))...); },
71-
static_cast<_Sender&&>(__sndr));
79+
return __apply(__mk_transform_fn(), static_cast<_Sender&&>(__sndr));
7280
}
7381
};
7482

test/stdexec/algos/adaptors/test_when_all.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
*/
1616

1717
#include <catch2/catch.hpp>
18+
#include <exec/any_sender_of.hpp>
1819
#include <exec/async_scope.hpp>
1920
#include <exec/env.hpp>
2021
#include <exec/sender_for.hpp>
@@ -461,4 +462,13 @@ namespace
461462
scope.request_stop();
462463
ex::sync_wait(scope.on_empty());
463464
}
465+
466+
TEST_CASE("regression test for #1988", "[adaptors][when_all")
467+
{
468+
// just test that this compiles:
469+
using any_sender = exec::any_sender<
470+
exec::any_receiver<ex::completion_signatures<ex::set_value_t(int), ex::set_value_t(double)>>>;
471+
ex::sync_wait(ex::when_all_with_variant(any_sender{ex::just(1)}));
472+
SUCCEED();
473+
}
464474
} // namespace

0 commit comments

Comments
 (0)