6

General-Purpose Utilities

The standard library contains many general-purpose utilities and libraries beyond the containers, algorithms, and iterators discussed in the previous chapter. This chapter is focused on three areas: the chrono library for working with dates, times, calendars, and time zones; type traits, which provide meta-information about other types; and utility types in newer versions of the standard, std::any, std::optional, and std::variant in C++17, std::span and std::source_location in C++20, and std::mdspan and std::expected in C++23.

The recipes included in this chapter are as follows:

  • Expressing time intervals with chrono::duration
  • Working with calendars
  • Converting times between time zones
  • Measuring function execution ...

Get Modern C++ Programming Cookbook - Third Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.