Search⌘ K
AI Features

Chapter Overview

Explore essential utility classes in C++ that help manage optional values, enforce type safety, measure time, use smart pointers, and generate random numbers. Understand how these utilities simplify complex tasks and improve code efficiency with practical examples.

We'll cover the following...

The C++ Standard Library includes an assortment of utility classes designed for specific tasks. Some are common, and we've probably seen many of these classes in other recipes in this course. This chapter covers a broad range of utilities, including time measurement, generic types, smart pointers, and more, in the following recipes:

  • Manage optional values with std::optional
  • Use std::any for type safety
  • Store different types with std::variant
  • Time events with std::chrono
  • Use fold expressions for variadic tuples
  • Manage allocated memory with std::unique_ptr
  • Share objects with std::shared_ptr
  • Use weak pointers with shared objects
  • Share members of a managed object
  • Compare random number engines
  • Compare random number distribution generators