Coroutine Types in the Coroutines Library
Get a detailed introduction to the coroutines library, supposedly a part of C++23.
We'll cover the following
The coroutines library, the modularized standard library, and the executors have something in common: they are supposed to be part of C++23.
Coroutines in C++20 are not more than a framework for the implementation of concrete coroutines. This means that it is up to the software developer to implement coroutines. The cppcoro library from Lewis Baker gives the first idea how a library of coroutines could look like. His library provides high-level coroutines, which C++20 does not offer.
🔑 Using cppcoro
The cppcoro library is based on the coroutines TS. The TS stands for technical specification and is the preliminary version of the coroutines functionality we get with C++20. Lewis will presumably port the cppcoro library from the coroutines TS to the coroutines defined in C++20. The library can be used on Windows (Visual Studio 2017) or Linux (Clang 5.0/6.0 and libc++). For my experiments, I used the following command line for all examples:
Build with cppcoro
-std=c++17
: support for C++17-fcoroutines-ts
: support for the C++ coroutines TS-Iinclude
: cppcoro headers-stdlib=libc++
: LLVM implementation of the standard librarylibcppcoro.a
: cppcoro libraryAs I already mentioned: when cppcoro is based on C++20 coroutines, you can use them with each compiler that supports C++20. Additionally, they give you a flavor for the concrete coroutines we may get with C++23.
In the rest of this section to the coroutines library, I want to demonstrate a few examples that show the power of coroutines. My demonstration starts with the coroutine types.
Get hands-on with 1400+ tech skills courses.