Search⌘ K

Chapter Overview

Explore significant new features introduced in C++20's Standard Template Library. Understand how to use the format library, compile-time constexpr vectors, the spaceship operator for comparisons, concepts for safer templates, and ranges for container views. This lesson prepares you to apply modern C++20 improvements in your projects and codebases.

We'll cover the following...

This chapter concentrates on some of the more compelling features that C++20 adds to the STL. We can use some of these right away. Others may need to wait for implementation in your favorite compiler. There are a lot of new additions to the C++20 standard, far more than we could cover here. We'll cover the additions that are most likely to have long-term impact.

In this chapter, we will cover the following recipes:

  • Format text with the new format library
  • Use compile-time vectors and strings with constexpr
  • Safely compare integers of different types
  • Use the spaceship operator <=> for three-way comparisons
  • Easily find feature test macros with the <version> header
  • Create safer templates with concepts and constraints
  • Avoid re-compiling template libraries with modules
  • Create views into containers with ranges

This chapter aims to familiarize you with these new features in C++20, so you may use them in your own projects and understand them when you encounter them.