Introducing the Boost.Cobalt library
We introduced how C++20 supports coroutines in Chapter 8. It was made obvious that writing coroutines is not an easy task due to two main reasons:
- Writing coroutines in C++ requires a certain amount of code to make the coroutine work but is not related to the functionality we want to implement. For example, the coroutine we wrote to generate the Fibonacci sequence was quite simple, but we had to implement the wrapper type, the promise, and all the functions required for it to be usable.
- The development of plain C++20 coroutines requires a good knowledge of the low-level aspects of how coroutines are implemented in C++, how the compiler transforms our code to implement all the mechanisms necessary to keep the coroutine state, and details about how the functions we must implement are called and when.
Asynchronous programming is difficult enough without all those many details. It would be much better if we could focus on our program...