C++20 Reference Card
C++20 Reference Card
While the C++20 Standard is still being finalised and polished, we know all of its core features. At first, the new specification of the language might sound...
Join the DZone community and get the full member experience.Join For Free
While the C++20 Standard is still being finalized and polished, we know all of its core features. At first, the new specification of the language might sound complex and overwhelming. That's why, if you want to have an overview of the core elements and get the bigger picture, you can have a look at my new reference card.
Want Your Own Copy to Print?
If you like, I prepared PDF which packs both language and the Standard Library features. Each item has a short description and an example if possible.
Here's what the text covers:
- Designated Initializers
- Range-based for with initializer
- New attributes
- Structured Bindings Updates
- Class non type template parameters
- Chrono Library Updates
- Multithreading and Synchronisation
- and many others
Special thanks to the CppPolska team, Andrzej Krzemienski (akrzemi1), Łukasz R., Yehezkel B., and many others from my mailing list — for valuable feedback about the features, typos, and other improvements.
All of the existing subscribers of my mailing list have already got the new document, so If you want to download it just subscribe here.
Please notice that along with the new ref card you'll also get C++17 language reference card that I initially published three years ago. With this "package" you'll quickly learn about all of the latest parts that Modern C++ acquired over the last few years.
Let's now go through some of the core parts of C++20.
Constrains on the template parameters and meaningful compiler messages in a case on an error. Can also reduce the compilation time.
Also with terse syntax:
The replacement of the header files! With modules, you can divide your program into logical parts.
Explicit member names in the initializer expression:
Range-Based for With Initialiser
Create another variable in the scope of the for loop:
[[likely]]- guides the compiler about more likely code path
[[unlikely]]- guides the compiler about uncommon code path
[[no_unique_address]]- useful for optimisations, like EBO
[[nodiscard]]for constructors - allows us to declare the constructor with the attribute. Useful for ctors with side effects, or RAII.
[[nodiscard("with message")]]- provide extra info
[[nodiscard]]is also applied in many places in the Standard Library
A new keyword that specifies an immediate function - functions that produce constant values, at compile time only. In contrast to
constexpr function, they cannot be called at runtime.
Plus many more like coroutines, constinit, CTAD updates and more!
Python-like formatting library in the Standard Library!
's` has a value of "-7-, 9--" centred, and then left aligned. It also supports the Chrono library and can print dates.
A radical change in how we work with collections! Rather than use two iterators, we can work with a sequence represented by a single object.
With Ranges, we also get new algorithms, views and adapters.
A non-owning contiguous sequence of elements. Unlike string_view, span is mutable and can change the elements that it points to.
Joining thread, semaphores, latches and barriers, Chrono library updates with calendar and timezones,
erase_if container functions, and many more!
I hope with this concise reference card it will be easier to understand the scope of the new Standard.
Do you like the new features of C++20? What's your favourite part? Let us know in comments.
The reference card presented on this page contains only one page. Hovewer there's also an extended 2-page version available for my Patrons! The first page describes language features, while the second one related to the library changes. See more on the "Extra Content!" page.
Published at DZone with permission of Bartłomiej Filipek , DZone MVB. See the original article here.
Opinions expressed by DZone contributors are their own.