Skip to content

Commit fdb7a74

Browse files
andreasbuhrlewissbaker
authored andcommitted
translate "for co_await" to regular for loops using "co_await"
"for co_await" was in the coroutine-ts but did not make it into the C++20 standard. This patch translates the "for co_await" which were used to standard for loops using "co_await". This is necessary to compile on MSVC 1928 in with c++-latest.
1 parent a5ed331 commit fdb7a74

File tree

3 files changed

+8
-4
lines changed

3 files changed

+8
-4
lines changed

include/cppcoro/resume_on.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,8 +117,9 @@ namespace cppcoro
117117
template<typename SCHEDULER, typename T>
118118
async_generator<T> resume_on(SCHEDULER& scheduler, async_generator<T> source)
119119
{
120-
for co_await(auto& value : source)
120+
for (auto iter = co_await source.begin(); iter != source.end(); co_await ++iter)
121121
{
122+
auto& value = *iter;
122123
co_await scheduler.schedule();
123124
co_yield value;
124125
}

test/async_generator_tests.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -271,8 +271,9 @@ TEST_CASE("large number of synchronous completions doesn't result in stack-overf
271271
auto consumer = [](cppcoro::async_generator<std::uint32_t> sequence) -> cppcoro::task<>
272272
{
273273
std::uint32_t expected = 0;
274-
for co_await(std::uint32_t i : sequence)
274+
for (auto iter = co_await sequence.begin(); iter != sequence.end(); co_await ++iter)
275275
{
276+
std::uint32_t i = *iter;
276277
CHECK(i == expected++);
277278
}
278279

test/scheduling_operator_tests.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,9 @@ TEST_CASE_FIXTURE(io_service_fixture, "schedule_on async_generator<> function")
8787
auto seq = schedule_on(io_service(), makeSequence());
8888

8989
int expected = 1;
90-
for co_await(int value : seq)
90+
for (auto iter = co_await seq.begin(); iter != seq.end(); co_await ++iter)
9191
{
92+
int value = *iter;
9293
CHECK(value == expected++);
9394

9495
// Transfer exection back to main thread before
@@ -177,8 +178,9 @@ TEST_CASE_FIXTURE(io_service_fixture, "resume_on async_generator<> function"
177178
auto seq = resume_on(otherIoService, makeSequence());
178179

179180
int expected = 1;
180-
for co_await(int value : seq)
181+
for (auto iter = co_await seq.begin(); iter != seq.end(); co_await ++iter)
181182
{
183+
int value = *iter;
182184
// Every time we receive a value it should be on our requested
183185
// scheduler (ie. main thread)
184186
CHECK(std::this_thread::get_id() == mainThreadId);

0 commit comments

Comments
 (0)