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]match.

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

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.

Constructors

this
this(T value)
this(const(T) value)
this(immutable(T) value)
this(Value value)

Constructs a SumType holding a specific value.

this
this(T value)

Constructs a SumType holding a specific value.

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

Constructs a SumType holding a specific value.

this
this(immutable(T) value)
Undocumented in source.
this
this(Value value)

Constructs a SumType holding a specific value.

this
this(Value value)
Undocumented in source.
this
this(inout(SumType) other)
this(SumType other)

Constructs a SumType that's a copy of another SumType.

this
this(SumType other)
Undocumented in source.
this
this(const(SumType) other)

Constructs a SumType that's a copy of another SumType.

this
this(const(SumType) other)
Undocumented in source.
this
this(immutable(SumType) other)

Constructs a SumType that's a copy of another SumType.

this
this(immutable(SumType) other)
Undocumented in source.
this
this()
Undocumented in source.

Destructor

~this
~this()

Calls the destructor of the SumType's current value.

Members

Aliases

Types
alias Types = AliasSeq!(ReplaceTypeUnless!(isSumTypeInstance, This, typeof(this), TemplateArgsOf!SumType))

The types a SumType can hold.

Functions

opAssign
SumType opAssign(T rhs)

Assigns a value to a SumType.

opAssign
SumType opAssign(T rhs)

Assigns a value to a SumType.

opAssign
SumType opAssign(SumType rhs)

Copies the value from another SumType into this one.

opAssign
SumType opAssign(SumType rhs)
Undocumented in source.
opAssign
SumType opAssign(SumType rhs)

Moves the value from another SumType into this one.

opEquals
bool opEquals(Rhs rhs)

Compares two SumTypes for equality.

toHash
size_t toHash()

Returns the hash of the SumType's current value.

toHash
size_t toHash()

Returns the hash of the SumType's current value.

toString
string toString()

Returns a string representation of the SumType's current value.

toString
void toString(Sink sink, FormatSpec!Char fmt)

Handles formatted writing of the SumType's current value.

toString
string toString()

Returns a string representation of the SumType's current value.

toString
void toString(Sink sink, FormatSpec!Char fmt)

Handles formatted writing of the SumType's current value.

See Also

Meta