Variant

Type that can hold one of the types listed as its template parameters.

$(D_PSYMBOL Variant) is a type similar to $(D_KEYWORD union), but $(D_PSYMBOL Variant) keeps track of the actually used type and throws an assertion error when trying to access an invalid type at runtime.

template Variant (
Specs...
) if (
isTypeTuple!Specs &&
NoDuplicates!Specs.length == Specs.length
) {}

Members

Structs

Variant
struct Variant
Undocumented in source.

Templates

accessor
template accessor(T, Union)
Undocumented in source.
accessorImpl
template accessorImpl(T, Union, size_t tag)
Undocumented in source.

Unions

AlignedUnion
union AlignedUnion(Args...)
Undocumented in source.

Parameters

Specs

Types this $(D_SPYBMOL Variant) can hold.

Examples

Variant!(int, double) variant = 5;
assert(variant.peek!int);
assert(variant.get!int == 5);

variant = 5.4;
assert(!variant.peek!int);
assert(variant.get!double == 5.4);

Meta