To paraphrase Henry Ford, an object of type std::variant<A, B, C> can hold a value
of any type--as long as it's A, B, or C. But suppose we wanted to hold a value of truly any type? Perhaps our program will load plugins at runtime that might contain new types impossible to predict. We can't specify those types in a variant. Or perhaps we are in the "recursive data type" situation detailed in the preceding section.
For these situations, the C++17 standard library provides an algebraic-data-type version of "infinity": the type std::any. This is a sort of a container (see Chapter 4, The Container Zoo) for a single object of any type at all. The container may be empty, or it may contain an object. You can perform the following fundamental operations on an any object:
- Ask if it currently holds an object
- Put a new...