dmd.root.optional

Implementation of an 'Optional' type

Members

Structs

Optional
struct Optional(T)

Optional type that is either empty or contains a value of type T

Examples

import core.exception : AssertError;

Optional!int opt;
assert( opt.isEmpty());
assert(!opt.isPresent());
assert(!opt.hasValue(1));
assert(!opt.hasValue(2));

bool caught;
try
    cast(void) opt.get();
catch (AssertError)
    caught = true;
assert(caught);

opt = Optional!int(1);
assert(!opt.isEmpty());
assert( opt.isPresent());
assert( opt.get() == 1);
assert( opt.hasValue(1));
assert(!opt.hasValue(2));

Meta