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 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 ...

Get Modern C++ Programming Cookbook - Second 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.