January 2018
Intermediate to advanced
374 pages
9h 53m
English
If we can trade off the ability to store any type in the container and, rather, concentrate on a fixed set of types declared at the container initialization, then std::variant is a better choice.
The std::variant has two main advantages over std::any:
The std::variant works in a somewhat similar manner to a tuple, except that it only stores one object at a time. The contained type and value is the type and value you assigned it last. Look at the following image: