Introduction to Coroutines
Explore the concept of coroutines introduced in C++20 and understand how co_await and co_yield extend function execution to support asynchronous programming and lazy evaluation. Learn to implement generator functions that produce data streams efficiently without blocking program execution.
We'll cover the following...
Coroutines are functions that can suspend and resume their execution while keeping their state. The evolution of functions goes one step further in C++20.
What I present in this section as a new idea in C++20 is actually quite old. The term coroutine was coined by Melvin Conway; He used it in his publication on compiler construction in 1963. Likewise, 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 will extend the execution of a C++ function with two new concepts.
Thanks to ...