dyaml.stdsumtype

This module was copied from Phobos at commit 87c6e7e35 (2022-07-06). This is necessary to include https://github.com/dlang/phobos/pull/8501 which is a fix needed for DIP1000 compatibility. A couple minor changes where also required to deal with package(std) imports.

SumType is a generic discriminated union implementation that uses design-by-introspection to generate safe and efficient code. Its features include:

* [Pattern matching.]match * Support for self-referential types. * 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). * Compatibility with BetterC.

Members

Classes

MatchException
class MatchException

Thrown by tryMatch when an unhandled type is encountered.

Functions

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

Structs

SumType
struct SumType(Types...)

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

This
struct This

Placeholder used to refer to the enclosing SumType.

Templates

canMatch
template canMatch(alias handler, Ts...)

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

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

isSumType
enum bool isSumType(T);

True if T is a SumType or implicitly converts to one, otherwise false.

Meta

License

Boost License 1.0

Authors

Paul Backus