Quickest way to learn is to be inquisitive about everything!
It starts with “how?”
std::variant
is a new addition to C++ standard library adopted from ominous
boost
libraries. Just as a reminder, std::variant
is a type safe union
with a very cool visitor interface, thanks to which handling its state is very
convenient. The type itself wouldn’t be very special to me until I stumbled
upon this sentence on
cppreference
As with unions, if a variant holds a value of some object type T, the object representation of T is allocated directly within the object representation of the variant itself. Variant is not allowed to allocate additional (dynamic) memory.