dmd.root.optional
Implementation of an 'Optional' type
License
Source: root/optional.d
Documentation: https://dlang.org/phobos/dmd_root_optional.html
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));
-
Declaration
structOptional(T);Optionaltype that is eitheremptyor contains a value of typeT-
Declaration
this(Tvalue);
static Optional!Tcreate(Tval);Creates an
Optionalwith the givenvalue -
Declaration
const boolisPresent();Return Value
Whether this
Optionalcontains a value -
Declaration
const boolisEmpty();Return Value
Whether this
Optionaldoes not contain a value -
Declaration
inout inout(T)get();Return Value
The value if present
-
Declaration
const boolhasValue(const Texp);Return Value
Whether this
Optionalcontains the supplied value
-