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).

Public Imports

std.variant
public import std.variant : This;

This placeholder, for use in self-referential types.

Members

Classes

MatchException
class MatchException

Thrown by tryMatch when an unhandled type is encountered.

Functions

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

Structs

SumType
struct SumType(TypeArgs...)

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

Templates

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.

Variables

canMatch
enum bool canMatch(alias handler, T);

True if handler is a potential match for T, otherwise false.

isSumType
enum bool isSumType(T);

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

Meta

Authors

Paul Backus, Atila Neves