C++20 will be the next big C++ standard after C++11. As C++11 did, C++20 will change the way we program modern C++. This change is particularly true for Ranges, Coroutines, Concepts, and Modules. To understand this next big step in the evolution of C++, let me put it in this post in the historical context of C++ standards.
The C++ Standards
At the end of the 80ths, Bjarne Stroustrup and Margaret A. Ellis wrote their famous book Annotated C++ Reference Manual (ARM). These books served two purposes. First, there were many independent C++ implementations. ARM defined, therefore, the functionality of C++. Second, ARM was the base for the first C++ standard: C++98 (ISO/IEC 14882). C++98 had a few important features: templates, the standard template library (STL) with its containers and algorithms, strings, and IO streams.
With C++03 (14882:2003), C++98 got a technical correction that is so small that there is no place on my timeline. In the community, C++03, which includes C++98, is called legacy C++.
In 2005 something exciting happened. The so-called technical report 1 (TR1; ) was published. TR1 was a big step toward C++11 and, therefore, toward Modern C++. TR1 (TR 19768) is based on the boost project founded by members of the C++ standardization committee. TR1 has 13 libraries that should become part of the next C++ standard. For example, the library to the regular expression library, the random number library, smart pointers such as std::shared_ptr, and hashtables. Only the so-called special mathematic functions had to wait until C++17.
C++11 stands for the next C++ standard, but we call it Modern C++. This name also holds for C++14 and C++17. C++11 has many features which fundamentally changed the way we program C++. For example, C++11 brought the components of the TR1, but also move-semantic, perfect forwarding, variadic templates, or constexpr. But this is not all. With C++11, we got a memory model as the fundamental threading base and a threading API. If you are curious, here are my post on the memory model and multithreading in general.
C++14 is a small C++ standard. It brought read-writer locks, generalized lambdas, and generalized constexpr functions.
C++17 is neither big nor small. It has two outstanding features: the parallel STL and the standardized filesystem. About 80 algorithms of the STL can be executed with a so-called execution policy. This means a call std::sort(std::execute::par, vec.begin(), vec.end()) is a hint for the C++ implementation to sort the container vec in a parallel way. Additionally, you can specify that the sort should be done sequentially (std::execution::seq) or vectorized (std::execution::par_unseq). As for C++11, boost was also highly influential for C++17. We got the filesystem from boost and the three new data types: std::optional, std::variant, and std::any. Here are my posts to C++17.
C++20 will change the way we program C++ as fundamentally as C++11. This holds, in particular, for the big four: Ranges, Coroutines, Concepts, and Modules. A half year ago, I would write the big five, but contracts were removed in the standardization meeting this year in Cologne. A contract specifies in a precise and checkable way interfaces for software components. My post, C++ Core Guidelines: A Short Detour to Contracts in C++20, gives you more details. I should not write about the past. Here is the bright shining, upcoming future.
The new ranges library enables it to express algorithms directly on the container, compose the algorithm with the pipe symbol and apply them to infinite data streams.
Thanks to Coroutines, asynchronous programming in C++ may become mainstream. Coroutines are the base for cooperative tasks, event loops, infinite data streams, or pipelines.
Concepts will change the way we think and program templates. They are semantic categories for valid template arguments. They enable you to express your intention directly in the type of system. If something goes wrong, you will get a short error message.
Modules will overcome the restrictions of header files. They promise a lot. For example, the separation of header and source files becomes as obsolete as the preprocessor. Ultimately, we will also have faster build times and an easier way to build packages.
But this by far not all. Here are a few additional highlights:
- the three-way comparison operator <=>
- strings literals as template parameters
- calendar and time-zone extensions of the chrono library
- std::span as a view on a contiguous array
- constexpr virtual function
- redefinition of volatile
- additions to the atomics: std::atomic_ref<T> and std::atomic<std::shared_ptr<T>>; waiting on atomics
- new synchronization mechanisms such as semaphores, latches, and barriers
- constexpr containers such as std::string and std::vector
- an improved thread std::jthread, which joins automatically and can be stopped
Okay, we should give the new child a name because the existing C++ standards have all informal names.
- Legacy C++: C++98, and C++03
- Modern C++: C++11, C++14, and C++17
- <To be filled>: C++20, C++23 …
This name discussion is difficult. In April, I had the same question on Twitter. Here is the tweet,
How should we call C++20 and the beyond area?
C++98 – C++03: Legacy C++
C++11 – C++17: Modern C++
C++20 – C++.. :
Honestly, I don’t know.
— Rainer Grimm (@rainer_grimm) April 28, 2019
and here are a few more than 50 answers. I added the Twitter names to the suggestions.
- indifferent penguin: Postmodern
- Ricardo: next generation
- Robert Ramey: The end of days
- Daniel Oliveira: C++ Reloaded/Revolution/Exoteric
- Michele Adduci: postmodern, post-postmodern, post-post-postmodern and so on
- Thomas Rodgers: C++ Endgame
- phlo81: new C++
- Eric Niebler: co_modular C++
- Martin Moene: Simple C++
- Andrey Upadyshev: C++ 2
- Joel F: Neon Genesis C++
- Breno G: C+=2
- Rasmus ‘Elg’ Bons: Futuristic C++
- Sebastian Rampe: new c++
- Dr James Smith: C++ Plus, C++ The Next Generation, C+++
- Richard Robinson: ++C
- Saurabh Purnaye: Ultra Modern cpp
- Alican Gültekin: C+++
- Alfonso Guerra: Neo-Futuris
- Improv: now C++
- Chris Blume Moderner C++
- Satay Das: New modern C++
- JustXtofl: post-20
- Adem Budak: Postconceptual C++
You see, there is a slight tendency to be postmodern. Maybe, you have a better idea.
Now, the questions challenged me the most. I have written ten posts in the last few years, with C++20 as their topic. My question was: Should I link to my existing posts or publish them again? The first way is incomplete, and the second way is redundant. I decided to pursue a third way. If possible, I will use the existing posts as a starting post but write them new. The reason is simple. First, I assume most of you don’t know my posts older than one year. Second, many of the features have changed since I wrote about them. My overall idea is to give you a complete post-series to C++20. Of course, I start with the big four.
Thanks a lot to my Patreon Supporters: Matt Braun, Roman Postanciuc, Tobias Zindl, G Prvulovic, Reinhold Dröge, Abernitzke, Frank Grimm, Sakib, Broeserl, António Pina, Sergey Agafyin, Андрей Бурмистров, Jake, GS, Lawton Shoemake, Jozo Leko, John Breland, Venkat Nandam, Jose Francisco, Douglas Tinkham, Kuchlong Kuchlong, Robert Blanch, Truels Wissneth, Kris Kafka, Mario Luoni, Friedrich Huber, lennonli, Pramod Tikare Muralidhara, Peter Ware, Daniel Hufschläger, Alessandro Pezzato, Bob Perry, Satish Vangipuram, Andi Ireland, Richard Ohnemus, Michael Dunsky, Leo Goodstadt, John Wiederhirn, Yacob Cohen-Arazi, Florian Tischler, Robin Furness, Michael Young, Holger Detering, Bernd Mühlhaus, Matthieu Bolt, Stephen Kelley, Kyle Dean, Tusar Palauri, Dmitry Farberov, Juan Dent, George Liao, Daniel Ceperley, Jon T Hess, Stephen Totten, Wolfgang Fütterer, Matthias Grün, Phillip Diekmann, Ben Atakora, Ann Shatoff, Rob North, Bhavith C Achar, and Marco Parri Empoli.
Thanks, in particular, to Jon Hess, Lakshman, Christian Wittenhorst, Sherhy Pyton, Dendi Suhubdy, Sudhakar Belagurusamy, Richard Sargeant, Rusty Fleming, John Nebel, Mipko, Alicja Kaminska, Slavko Radman, and David Poole.
|My special thanks to Embarcadero|
|My special thanks to PVS-Studio|
|My special thanks to Tipi.build|
|My special thanks to Take Up Code|
I’m happy to give online seminars or face-to-face seminars worldwide. Please call me if you have any questions.
- Embedded Programmierung mit modernem C++ 12.12.2023 – 14.12.2023 (Präsenzschulung, Termingarantie)
Standard Seminars (English/German)
Here is a compilation of my standard seminars. These seminars are only meant to give you a first orientation.
- C++ – The Core Language
- C++ – The Standard Library
- C++ – Compact
- C++11 and C++14
- Concurrency with Modern C++
- Design Pattern and Architectural Pattern with C++
- Embedded Programming with Modern C++
- Generic Programming (Templates) with C++
- Clean Code with Modern C++
- Phone: +49 7472 917441
- Mobil:: +49 176 5506 5086
- Mail: schulung@ModernesCpp.de
- German Seminar Page: www.ModernesCpp.de
- Mentoring Page: www.ModernesCpp.org
Modernes C++ Mentoring,