Coroutines
Coroutines are functions that can suspend and resume their execution while keeping their state. The evolution of functions goes in C++ one step further. Coroutines are with high probability part of C++20.
What I present in this section as a new idea in C++20 is quite old. The term coroutine was coined by Melvin Conway. He used it in his publication on compiler construction in 1963. Donald Knuth called procedures a special case of coroutines. Sometimes, it just takes a while to get your ideas accepted.
With the new keywords co_await
and co_yield
, C++20 extends the execution of C++ functions with two new concepts.
Thanks to co_await expression
it is possible to suspend and resume the execution of the expression
. If you use co_await expression
in a function func
, the call auto getResult = func()
does not block if the result of the function is not available. Instead of resource-consuming blocking, you have resource-friendly waiting.
co_yield expression
allows it to write a...