sumtype

A sum type for modern D.

SumType is an alternative to std.variant.Algebraic that features:

  • improved pattern-matching
  • full attribute correctness (pure, @safe, @nogc, and nothrow are inferred whenever possible)
  • a type-safe and memory-safe API compatible with DIP 1000 (scope)
  • no dependency on runtime type information (TypeInfo)

Members

Classes

MatchException
class MatchException

Thrown by tryMatch when an unhandled type is encountered.

Enums

isSumType
eponymoustemplate isSumType(T)

True if T is an instance of SumType, otherwise false.

Functions

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

Imports

This (from std.variant)
public import std.variant : This;

This placeholder, for use in self-referential types.

Structs

SumType
struct SumType(TypeArgs...)

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

Templates

canMatch
template canMatch(alias handler, T)

Checks whether a handler can match a given type.

match
template match(handlers...)

Calls a type-appropriate function with the value held in a SumType.

tryMatch
template tryMatch(handlers...)

Attempts to call a type-appropriate function with the value held in a SumType, and throws on failure.

Meta

Authors

Paul Backus, Atila Neves