Re:My tutorial and take on C++20 coroutines
by e12e on Monday February 22, 2021 @03:41PM
(#26230281)
So, given sibling comments on stack and function calls, this:
skip_iter(int skip, int stop)
for(int i=0;i<stop;i++)
Wouldn't work with complex types, boxed integers and so on? Because calling postfix ++ would be a function/method call?
Re:My tutorial and take on C++20 coroutines
by gpderetta on Tuesday February 23, 2021 @01:04PM
(#26240499)
Stackless coroutines can call other functions just fine (they would completely unusable otherwise). What they can't do is delegate suspension to any called function, i.e. any called function must return before the coroutine can yield as exactly one activation frame (the top level) can be suspended.
Re:My tutorial and take on C++20 coroutines
by klyrs on Monday February 22, 2021 @04:06PM
(#26230619)
That's just a simple example. I think the following should work, possibly with modification for forwarding:
class Stooge {...};
CoroutineIterator<Stooge> three_stooges() {
co_yield Stooge("Larry");
co_yield Stooge("Curly");
co_yield Stooge("Moe");
}
I just sat down with the tutorial and banged out what I consider to be a holy grail for quality of life. Alas, it's about 50 lines of ugly boilerplate. I'm omitting it, in part because it's untested, but mostly because I'm embarrassed to share that much C++ in a public forum. If anybody close to the C++ standards is listening... please make this boilerplate not suck so hard.