has

Checks whether a SumType contains a value of a given type.

The types must match exactly, without implicit conversions.

template has(T)
bool
has
(
Self
)
(
auto ref Self self
)
if ()

Members

Functions

has
bool has(Self self)

The actual has function.

Parameters

T

the type to check for.

Examples

Basic usage

SumType!(string, double) example = "hello";

assert( example.has!string);
assert(!example.has!double);

// If T isn't part of the SumType, has!T will always return false
assert(!example.has!int);

With type qualifiers

alias Example = SumType!(string, double);

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

assert( m.has!string);
assert(!m.has!(const(string)));
assert(!m.has!(immutable(string)));

assert(!c.has!string);
assert( c.has!(const(string)));
assert(!c.has!(immutable(string)));

assert(!i.has!string);
assert(!i.has!(const(string)));
assert( i.has!(immutable(string)));

Meta