Modern C++: C++17, C++20 and C++23
You write shorter, safer and faster modern C++ with move semantics, constexpr, optional, variant, expected, ranges and concepts.
Level 301 · 19 lessons · 15 practice labs
Lessons
Value categories and moving
- lvalues, rvalues and value categories
- Move semantics and std::move
- Perfect forwarding: forward and forwarding references
- Copy elision and return value optimisation
- Short task: count copies and moves
Modern language features
- Lambda captures and the dangling-reference trap
- constexpr and consteval: computing at compile time
- optional, variant and visit
- Error handling without exceptions using std::expected
- Structured bindings and if with an initialiser
- std::format and std::print
- Short task: a config loader that returns expected
C++20 and beyond
- Ranges and views: filter, transform, take
- Readable template errors with concepts
- Three-way comparison: <=>
- An introduction to modules: building with import
- An introduction to coroutines: writing a generator
- Short task: turn loops into a ranges pipeline
Capstone
- Capstone: migrate an old C++98 codebase to modern C++
Practice labs
- Counting copies and moves: Measure with a counting type how many copies and moves each way of adding to a vector makes and bring it to zero copies with emplace_back.
- Making a move constructor noexcept: Find why a class is copied rather than moved when the vector grows, make its move functions noexcept and pass the copy-counter test.
- Writing a factory with perfect forwarding: Fix a factory template that copies its arguments needlessly with std::forward and show by test that value categories are kept and the return copy is elided.
- Producing a table at compile time: Generate a checksum table at compile time with a constexpr function and verify a few values with static_assert.
- Moving a unique_ptr into a lambda: Move a non-copyable resource into a lambda with an init capture and show the task queue compiles and works correctly.
- Repairing a lambda that captures a dangling reference: Show with ASan the undefined behaviour in a callback that captures a local by reference and runs later, then pass the tests by fixing the capture.
- Signalling a missing record with optional: Change a lookup that returns an empty object when nothing is found to return std::optional and update the callers.
- Handling event types with variant and visit: Hold login, logout and error events in a std::variant, handle them with visit and show the compiler catches a missing branch when a type is added.
- Rewriting a settings loader with expected: Rewrite an exception-throwing settings loader to return std::expected, separate and chain the error types and cover every error path with tests.
- Simplifying a map loop with structured bindings: Simplify map loops written with first and second using structured bindings and if with an initialiser while the output stays the same.
- Aligning a report with std::format: Rewrite a stock report written with printf using std::format while keeping column widths, alignment and decimal precision.
- Comparing version numbers with <=>: Replace six hand-written comparison operators with one three-way comparison, order pre-release tags correctly too and pass the sorting tests.
- Turning a loop into a ranges pipeline: Write the loop that upper-cases the names of active users and takes the first five using filter, transform and take views.
- Constraining a template with a concept: Add your own concept to an average template that gives pages of errors for a wrong type and show the error message becomes short.
- Writing a line generator with a coroutine: Write a coroutine generator that lazily yields a file line by line and show that an abandoned generator closes the file and leaks nothing.
About this course
You write shorter, safer and faster modern C++ with move semantics, constexpr, optional, variant, expected, ranges and concepts.
What you will learn
- Value categories and moving
- Modern language features
- C++20 and beyond
- Capstone
Prerequisites
You should be comfortable with the level 101 and 201 topics of the same path.
Lab environment
Lessons run in your own Kali Linux terminal that opens in the browser. Nothing to install; the lab starts clean in every lesson.
Frequently asked questions
- Is this course right for my level?
- The course is at level 301; it assumes you know the topics of the lower-level courses.
- Is there anything to install?
- No. Every lesson runs in your own lab environment that opens in the browser.
- How do lessons work?
- Each lesson has 8 to 10 steps and a short quiz. Early steps show the command to type, later steps give less help; if two attempts fail, the solution opens.
- Can I try it for free?
- Yes. The first three lessons of every course are free.