Coroutines: Don’t try this at home

By Lieven de Cock

In C++20 we got the core language feature “coroutines”. Mostly oriented to the advanced C++ programmers, and not for the mere mortals, since it requires a lot of boilerplate one would not like to write. It provides the fundamentals to further build upon. Unfortunately the STL library did not build on it yet, more was to come in C++23. In C++23 we will only get one follow up: std::generator. So let’s revisit coroutines. What are they? A function that can be suspended and resumed. Easily said, but how to make use of it and write that boilerplate after all. We will look at the coroutine from 2 different angles: the user code and the compiler, and we will inspect what each wants or would like to have, and where we need to glue them together and what is needed for that purpose. We will give insights on topics like: coroutine frame, coroutine handle, promise_type, awaiters, awaitables, the interface or api.





Your Privacy

By clicking "Accept Non-Essential Cookies" you agree ACCU can store non-essential cookies on your device and disclose information in accordance with our Privacy Policy and Cookie Policy.

Current Setting: Non-Essential Cookies REJECTED


By clicking "Include Third Party Content" you agree ACCU can forward your IP address to third-party sites (such as YouTube) to enhance the information presented on this site, and that third-party sites may store cookies on your device.

Current Setting: Third Party Content EXCLUDED



Settings can be changed at any time from the Cookie Policy page.