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.

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)

Constructs a SumType holding a specific value.

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

Constructs a SumType that's a copy of another SumType

this
this()
Undocumented in source.

Destructor

~this
~this()

Calls the destructor of the SumType's current value.

Postblit

this(this)
this(this)

@disabled if any member type is non-copyable.

Members

Aliases

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

The types a SumType can hold.

Functions

opAssign
void opAssign(T rhs)

Assigns a value to a SumType.

opAssign
void opAssign(SumType rhs)

Copies the value from another SumType into this one.

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

Moves the value from another SumType into this one.

opEquals
bool opEquals(SumType rhs)

Compares two SumTypes for equality.

toString
string toString()
Undocumented in source. Be warned that the author may not have intended to support it.

Bugs

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

See Also

std.variant.Algebraic

Meta