Struct std.sumtype.SumType
A [tagged union](https://en.wikipedia.org/wiki/Tagged_union) that can hold a single value from any of a specified set of types.
struct SumType(Types...)
if (is(NoDuplicates!Types == Types) && (Types .length > 0));
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](#basic-usage) 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](#arithmetic-expression-evaluator) for
usage.
A SumType is initialized by default to hold the value of its
first member type, just like a regular union. The version identifier
SumTypeNoDefaultCtor can be used to disable this behavior.
Constructors
| Name | Description |
|---|---|
this
(value)
|
Constructs a SumType holding a specific value.
|
this
(other)
|
Constructs a SumType that's a copy of another SumType.
|
Methods
| Name | Description |
|---|---|
opAssign
(rhs)
|
Assigns a value to a SumType.
|
opAssign
(rhs)
|
Copies the value from another SumType into this one.
|
opAssign
(rhs)
|
Moves the value from another SumType into this one.
|
opEquals
(rhs)
|
Compares two SumTypes for equality.
|
toHash
()
|
Returns the hash of the SumType's current value.
|
toString
()
|
Returns a string representation of the SumType's current value.
|
toString
(sink, fmt)
|
Handles formatted writing of the SumType's current value.
|
Aliases
| Name | Description |
|---|---|
Types
|
The types a SumType can hold.
|
See Also
Authors
Paul Backus
License
Boost License 1.0