SumType

A tagged union that can hold a single value from any of a specified set of types.

The value in a SumType can be operated on using pattern matching.

The special type This can be used as a placeholder to create self-referential types, just like with Algebraic. See the "Arithmetic expression evaluator" example for usage.

A SumType is initialized by default to hold the .init value of its first member type, just like a regular union. The version identifier SumTypeNoDefaultCtor can be used to disable this behavior.

To avoid ambiguity, duplicate types are not allowed (but see the "basic usage" example for a workaround).

Constructors

this
this(T val)
this(const(T) val)
this(immutable(T) val)

Constructs a SumType holding a specific value.

this
this(const(T) val)
Undocumented in source.
this
this(immutable(T) val)
Undocumented in source.
this
this()
Undocumented in source.

Destructor

~this
~this()

Calls the destructor of the SumType's current value.

Postblit

this(this)
this(this)

Calls the postblit of the SumType's current value.

Members

Aliases

Types
alias Types = AliasSeq!(ReplaceType!(This, typeof(this), TypeArgs))

The types a SumType can hold.

Functions

opAssign
void opAssign(T rhs)

Assigns a value to a SumType.

opEquals
bool opEquals(SumType rhs)

Compares two SumTypes for equality.

toString
string toString()

Returns a string representation of a SumType's value.

Bugs

Types with @disabled opEquals overloads cannot be members of a SumType.

See Also

std.variant.Algebraic

Meta