With the new C++ coroutines, is it possible to define a coroutine class that I can use to yield from functions without returning a value? Or does yield always have to return something? I'm just interested in the yielding functionality, not a yielded value.
I want this:
Coro Fn() {
if (...) co_yield;
co_return;
}
Not this:
Coro Fn() {
if (...) co_yield dummyValue;
co_return dymmyValue;
}
No, some expression must follow the co_yield operator. However, you do not need to use the yielded value. You can simply ignore it.
For example, yield a message:
co_yield "ignore";
And add this to your promise_type:
auto yield_value(const char*) {
return std::suspend_always{};
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With