cpp/utility/variant

The class template represents a type-safe. An instance of at any given time either holds a value of one of its alternative types, or in the case of error - no value (this state is hard to achieve, see ).

As with unions, if a variant holds a value of some object type, the object representation of is allocated directly within the object representation of the variant itself. Variant is not allowed to allocate additional (dynamic) memory.

A variant is not permitted to hold references, arrays, or the type. Empty variants are also ill-formed ( can be used instead).

A variant is permitted to hold the same type more than once, and to hold differently cv-qualified versions of the same type.

Consistent with the behavior of unions during aggregate initialization, a default-constructed variant holds a value of its first alternative, unless that alternative is not default-constructible (in which case the variant is not default-constructible either). The helper class can be used to make such variants default-constructible.