Search⌘ K
AI Features

Chapter Overview

Explore new general STL features introduced in C++20 that improve code safety and clarity. Understand how to use span for safer arrays, structured bindings, if constexpr, and template argument deduction to write cleaner and more readable C++ code.

We'll cover the following...

This chapter is a general potpourri of STL features and techniques. These are mostly new features introduced over the past few years, which may not yet be widely used. These are useful techniques that will improve the simplicity and readability of your code.

In this chapter we will cover the following recipes:

  • Use the new span class to make our C-arrays safer
  • Use structured binding to return multiple values
  • Initialize variables within if and switch statements
  • Use template argument deduction for simplicity and clarity
  • Use if constexpr to simplify compile-time decisions