Programming in C++20
Course objectives
Delegates will learn:
- spaceship operator - implementation of comparisons in C++20
- new template features, such as concepts, template constraints, and the use of auto in template function declarations
- Ranges library - a new standard for collection processing in C++20
- new lambda expressions
- implementation of coroutines
- modularization of code – modules
- new API for multithreaded code
Course syllabus
Comparisons and <=> operator
- Safe comparisons for integral values
- Rewriting comparisons by compiler
- Defining operator
==
and operator<=>
for structs & classes - Using comparison categories with operator
<=>
- Using operator
<=>
in generic code
Placeholder auto for function parameters
- Using
auto
as a placeholder for function parameters - auto functions vs. generic lambdas
Constraints, requirements and concepts
- Constraints for templates
requires
clause- Ad hoc Boolean expressions
- Using traits as constraints
- Expression
requires
- Concepts
- Defining concepts
- Using concepts
- Subsuming concepts
- Semantic constraints
- Standard concepts
- Basic standard concepts
- Concepts for iterators and ranges
- Concept for callable objects
- Auxiliary concepts
Ranges library in C++20
- Algorithms accepting ranges as input parameters
- Sentinels
- Projections
- Views
- Generating Views
- Filtering Views
- Transforming Views
- Mutating Views
- Utilities for ranges and views
- Borrowed iterators and ranges
New features in the core language
- Range-based loop with initialization
- Enumerations and using declaration
- Aggregates and designated initializers
- New attributes
- Feature test macros
New features in the standard library
std::span
- Formatted output –
std::format
- Dates and time zones
- New type traits
- Mathematical constants
- Bit operations in C++20
New features for lambda expressions
- Generic lambdas with template parameter
- Default constructors for lambdas
- Lambdas as Non-Type Template Parameters
- Consteval lambdas
Compile-time computations
constinit
consteval
constexpr
in C++20- Writing
constexpr
functions using heap allocations (std::vector
orstd::string
)
Coroutines
- Defining and using coroutine
- Coroutine frame, coroutine handle & promise type
- Using heap memory in coroutines
- Generators
- Awaitables and awaiters
- Coroutines and concurrency
Modules
- Implementing and exporting modules
- Compiling module units
- Importing and using modules
- Modules with multiple files
- Module units
- Internal partitions
- Interface partitions
New concurrency features
std::jthread
and stop tokens- Semaphores
- New features for atomic types
- Synchronized output streams
Prerequisites
Working knowledge of C++11/14/17