Class - Programming with C++20
You are already using C++11 or newer and like to upgrade your knowledge with all the great new elements of C++20? Then join this course!
Course Description
You will start learning about one of C++20's biggest revolutions, Concepts. They make templates way less scary and, at the same time, give your more fine control to specify the interfaces of your templates. You learn how Concepts work and how to create your own Concept. Your learning continues by looking at a new form of writing function templates: abbreviated function templates. In the end, you learn how Concepts improve error messages.
Your next stop is coroutines. They are a beautiful new way to write asynchronous code leaving the heavy lifting to the compiler. This feature can reduce your finite state machines big time. You learn to rethink how function calls work and how regular functions compare to Coroutines. After that, you familiarize yourself with the low-level Coroutine API C++20 offers. You then learn how to use that knowledge to build a byte-stream parser using a Coroutine.
While you have seen two big language updates at this point, you will now learn about the improvements of the STL: ranges. You will also learn about the improvements Ranges give you, like the unintentional use of a temporary, which is no longer valid.
Ranges are followed by the new ways of formatting a string using std::format
. You will learn how std::format
combines the best parts of iostreams and snprintf
. Part of this learning is using std::format
together with a custom buffer,
You will then learn how easy comparisons can be in C++20 and how much less code you have to write to create a simple class that supports all six comparisons. The start is a recap of what you had to do before C++20, followed by how your code now boils down to just a few lines of code using the spaceship operator and a new compiler ability called operator-rewrites. You will then learn about some situations where upgrading C++17 code could lead to unexpected issues.
You started learning about a huge part of the improvements to templates with Concepts, but there is more. It is time to learn about the new types you can use as non-type template parameters.
Of course, you will also learn about minor elements like starts_with
for std::string
or std::source_location
to further remove the need for macros.
Every release since C++11 did improve the things we can do with constexpr
. C++20 is no exception. Besides the new things you can do in constexpr
-context, you will also learn about two new elements of the constexpr
-family: consteval
and constinit
. In the end, you will be able to set all three in a complete picture knowing which one of them to use when best.
After the seminar, you will clearly understand what C++20 adds to the plate. You can consciously select features from the new language standard for a project and use them safely.
Course Outline
- C++20 language updates
- Aggregate initialization with designated initializers
- Parenthesis initialization for aggregates
- range-based
for
with initializer using
forenum
's- Threeway comparisons: Simplify your comparisons
- Template updates
- Concepts: Predicates for strongly typed generic code
- Class types as non-type template parameters
- More CTAD
- Coroutines: Resumable functions
- Ranges: The next-generation STL
- Modules: The superior way of includes
- Lambda's in C++20: What's new
- Compute more things at compile-time
- Allocate dynamic memory during compile-time
- Execute function guaranteed at compile-time
- Initialize variables at compile-time with the ability to change them later
- New STL elements
std::format
: Modern & type-safe text formattingspan
source_location
std::string
:starts_with
andends_with
contains
for all associative containersstd::jthread
std::erase
andstd::erase_if
Included in this course are
- A handout as color PDF, which includes all references and an acronyms list;
- The source code for the exercises as well as sample solutions for all exercises as a ZIP-file;
- Certificate of attendance;
- A complimentary copy one of my books