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
struct
Optional
(T);Optional
type that is eitherempty
or contains a value of typeT
-
Declaration
this(T
value
);
static Optional!Tcreate
(Tval
);Creates an
Optional
with the givenvalue
-
Declaration
const bool
isPresent
();Return Value
Whether this
Optional
contains a value -
Declaration
const bool
isEmpty
();Return Value
Whether this
Optional
does not contain a value -
Declaration
inout inout(T)
get
();Return Value
The value if present
-
Declaration
const bool
hasValue
(const Texp
);Return Value
Whether this
Optional
contains the supplied value
-