C++20: The Complete Guide
C++20: The Complete Guide
Summary:
Introduction
The book "C++20: The Complete Guide" (original title — C++20: The Complete Guide) by Nicolai Josuttis is not just another publication about a programming language. It is a fundamental work that is rightfully considered one of the most authoritative sources on the C++20 standard. Published in 2022, the book, with a volume of 476 pages, covers all the key innovations that have radically changed the face of the language. For the educational website PythonLib, focused on deep understanding of technologies, this book will be an ideal bridge between classic C++ and its modern paradigm.
What is this book about?
Nicolai Josuttis, known for his works "C++17: The Complete Guide" and "The C++ Standard Library," once again demonstrates mastery in explaining complex topics. The book is dedicated exclusively to the new features introduced in the C++20 standard. The author does not rewrite the basics, but focuses on the four "pillars" of the update: Concepts, Coroutines, Modules, and Ranges. In addition, less extensive but important improvements are discussed in detail: the three-way comparison (operator <=>), initializers in range-based for, improved constant expressions (constexpr), new attributes, and much more.
Who is this book for?
This edition is strictly for experienced developers. If you are just starting to learn C++ or are not familiar with C++11/14/17, the book will seem difficult to you. Josuttis assumes that the reader is confident with templates, lambda expressions, move semantics, and the standard library. The book is ideal for:
- Programmers transitioning from C++17 to C++20;
- Library and framework developers;
- Software architects wanting to adopt modern idioms;
- Educators who want to stay up-to-date with the latest standards.
What will the reader learn?
After reading, you will be able to confidently apply the following features in practice:
- Concepts: how to impose constraints on template parameters, making code self-documenting and improving error messages;
- Coroutines: a mechanism for writing asynchronous code, generators, and lazy computations without third-party libraries;
- Modules: replacing the outdated header file model, speeding up compilation, and isolating code;
- Ranges Library: composing algorithms in a functional programming style, working with infinite sequences;
- Spaceship operator (<=>): automatic generation of comparison operators;
- constexpr expansion: performing complex computations at compile time (including dynamic memory allocation and virtual functions);
- New types and syntax: char8_t, initializers in for, designated initializers, and other small improvements simplifying everyday work.
Strengths of the book
The first thing that stands out is the structure. Each chapter is dedicated to one feature and is built on the principle "from simple to complex." Josuttis does not just list syntax, but explains the motivation: why this feature was added, what problems it solves, and what pitfalls exist. The second is practical orientation. The example code can be downloaded from the author's GitHub, and it actually works with modern compilers (GCC, Clang, MSVC). The third is honesty. The author openly talks about the immaturity of some features (for example, modules still have limited support), which saves from disappointment when trying to compile.
The chapter on coroutines deserves special mention. This is perhaps the most complex topic in C++20, and Josuttis handles it brilliantly, dissecting the internal structure of the coroutine framework (promise_type, awaitable, awaiter) with simple examples.