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 the new C++17 types std::any
, std::optional
, and std::variant
and the C++20 type std::span
.
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 time with a standard clock
- Generating hash values for custom types
- Using
std::any
to store any value - Using
std::optional
to store optional values - Using
std::variant
as a type-safe union - Visiting an
std::variant
- Using
std::span
for contiguous sequences of objects - Registering...