What’s new in this edition
This section provides a list of new or updated recipes along with a short description of the change.
Chapter 1, Learning Modern Core Language Features:
- Using scope enumeration: updated with C++23
std::to_underlying
andstd::is_scoped_enum
- Using range-based for loops to iterate on a range: updated with the C++23
init
statement - Using the subscript operator to access elements in a collection: (new) C++23 multidimensional subscript operator
Chapter 2, Working with Numbers and Strings:
- Understanding the various numeric types: (new) explains the C++ numerical types
- Understanding the various character and string types: (new) explains the C++ character types
- Printing Unicode characters to the output console: (new) discusses working with UNICODE and printing to the console
- Creating a library of string helpers: updated with C++20
starts_with()
,ends_with()
, andcontains()
- Formatting and printing text with std::format and std::print: updated with C++23
std::print()
andstd::println()
- Using std::format with user-defined types: updated with C++23
std::formattable
and better examples
Chapter 3, Exploring Functions:
- Using lambdas with standard algorithms: updated with C++23 attributes on function call operators
- Writing a recursive lambda: updated with C++14 recursive generic lambdas
- Writing function templates: (new) a walkthrough of writing function templates
Chapter 4, Preprocessing and Compilation:
- Conditionally compiling your source code: updated with C++23
#warning
,#elifdef
, and#elifndef
- Performing compile time assertion checks with static_assert: updated with C++26 user-generated messages
- Providing metadata to the compiler with attributes: updated with C++23 attributes on lambda,
[[assume]]
, and duplicate attributes
Chapter 5, Standard Library Containers, Algorithms, and Iterators:
- Using vector as default container: updated with C++23 range-aware member functions
- Selecting the right standard containers (new) a comparison of standard containers
Chapter 6, General-Purpose Utilities:
- Working with calendars: updated with C++20-compliant examples
- Converting times between timezones: updated with C++20-compliant examples
- Chaining together computations which may or may not produce a value: (new) discusses the C++23
std::optional
monadic operations - Using std::expected for returning a value or an error: (new) discusses the C++23
std::expected
type - Using std::mdspan for multidimensional views of sequences of objects: (new) explores the C++23
std::mdspan
type - Providing logging details with source_location: (new) explores the C++20
std::source_location
type - Using the stacktrace library to print the call stack: (new) teaches the C++23 stacktrace library
Chapter 7, Working with Files and Streams:
- Using streams on fixed-size external buffers: (new) explores the C++23 span buffers
Chapter 8, Leveraging Threading and Concurrency:
- Using thread synchronization mechanisms: updated with C++20-compliant samples
- Synchronizing output streams: (new) discusses the C++20 sync streams
Chapter 9, Robustness and Performance:
- Creating compile-time constant expressions: updated with C++23 static
constexpr
variables - Optimizing code in constant-evaluated contexts: (new) explains the C++23 if
consteval
- Using virtual function calls in constant expressions: (new) discusses the C++20
constexpr
virtual functions
Chapter 10, Implementing Patterns and Idioms:
- Adding functionality to classes with mixins: (new) explains the mixins pattern
- Handling unrelated types generically with type erasure: (new) discusses the type erasure idiom
Chapter 11, Exploring Testing Frameworks:
- Getting started with Catch2: updated installation instructions for Catch2 version 3.4.0
- Asserting with Catch2: updated examples for Catch2 version 3.4.0
Chapter 12, C++20 Core Features:
- Exploring abbreviated function templates: (new) examines C++20 abbreviated function templates
- Exploring the standard range adaptors: (new) discusses the C++20 and C++23 range adaptors
- Converting a range to a container: (new) explains how to convert a range to a standard container using C++23
std::ranges::to()
- Using constrained algorithms: (new) explores the general-purpose algorithms that work directly with ranges
- Creating a coroutine task for asynchronous computation: updated with standard compliant examples (and alternatives with the libcoro library)
- Creating a coroutine generator type for sequences of values: updated with standard compliant examples (and alternatives with the libcoro library)
- Recursively generating values with the std::generator type: (new) explains the C++23
std::generator