Intro to C++ Coroutines: Concept -- Ilya Doroshenko
The time has come, fellow devs. We are on our way to uncover the newest concept of C++ language – Coroutines.
Intro to C++ Coroutines: Concept
By Ilya Doroshenko
From the article:
The newest concept of C++ language, Coroutines, is already used by several programming languages, like
- C# async tasks and yield iterables, forming LINQ base;
- JS with awaitables, replacing the old way of making consecutive calls, that was hard to understand did a lot of code identation for cases that required a lot of async execution;
- Python with synchronous generator
- etc.
They were introduced in the recent C++20 standard. However, instead of handy classes such as
Task<>andstd::generator<>we received a complex and low-level toolkit to make our own promises and futures. Only C++23 gave us our first usable coroutine type (std::generator<>). It seems like the C++ committee followed the quote: “give a man a fish and you feed him for a day; teach a man to fish and you feed him for a lifetime”.Today we will discuss what is needed to understand coroutines, and in the later chapters we will make our own little coroutine.

In this article, we delve into the equivalent helper functions for C# and JavaScript, which are simpler due to the inherent behavior of references in these languages, eliminating the need for explicit shared pointer conversions.
A code design pattern I’ve used a lot in recent times is the “optional-based polymorphism” that looks like a delegation to another type that might not be available. It might be an implementation of the FCoI-principle (Favour Composition over Inheritance).
A new episode of the series about SObjectizer and message passing: