From d6a041224cc7c6f3150bf81a0898dcf3b46fe39d Mon Sep 17 00:00:00 2001 From: Raymond Chen Date: Sun, 31 May 2020 07:48:53 -0700 Subject: [PATCH] Simply when_all implementation and test (#647) --- strings/base_coroutine_foundation.h | 2 +- test/test/when.cpp | 7 +++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/strings/base_coroutine_foundation.h b/strings/base_coroutine_foundation.h index 3a2a5d0f9..8b22caa1f 100644 --- a/strings/base_coroutine_foundation.h +++ b/strings/base_coroutine_foundation.h @@ -712,7 +712,7 @@ WINRT_EXPORT namespace winrt template Windows::Foundation::IAsyncAction when_all(T... async) { - ((co_await async, void()), ...); + (void(co_await async), ...); co_return; } diff --git a/test/test/when.cpp b/test/test/when.cpp index 27ce95551..86edc6c77 100644 --- a/test/test/when.cpp +++ b/test/test/when.cpp @@ -5,10 +5,13 @@ using namespace concurrency; using namespace winrt; using namespace Windows::Foundation; -struct CommaStruct +struct CommaStruct : std::experimental::suspend_never { // If the comma operator is invoked, we will get a build failure. CommaStruct operator,(CommaStruct) = delete; + + // Awaiting the object just returns itself. + auto await_resume() const { return *this; } }; task ppl(bool& done) @@ -56,7 +59,7 @@ TEST_CASE("when") when_all().get(); // Verify edge case of overloaded comma operator (shame on you). - when_all(create_task([] { return CommaStruct{}; }), create_task([] { return CommaStruct{}; })).get(); + when_all(CommaStruct{}, CommaStruct{}).get(); { handle first_event{ check_pointer(CreateEventW(nullptr, true, false, nullptr)) }; handle second_event{ check_pointer(CreateEventW(nullptr, true, false, nullptr)) };