get

Accesses a SumType's value.

The value must be of the specified type. Use has to check.

template get(T)
ref
T
get
(
Self
)
(
auto ref Self self
)
if ()

Members

Functions

get
T get(Self self)

The actual get function.

Parameters

T

the type of the value being accessed.

Examples

Basic usage

SumType!(string, double) example1 = "hello";
SumType!(string, double) example2 = 3.14;

assert(example1.get!string == "hello");
assert(example2.get!double == 3.14);

With type qualifiers

alias Example = SumType!(string, double);

Example m = "mutable";
const(Example) c = "const";
immutable(Example) i = "immutable";

assert(m.get!string == "mutable");
assert(c.get!(const(string)) == "const");
assert(i.get!(immutable(string)) == "immutable");

Meta