Report a bug
If you spot a problem with this page, click here to create a Bugzilla issue.
Improve this page
Quickly fork, edit online, and submit a pull request for this page.
Requires a signed-in GitHub account. This works well for small changes.
If you'd like to make larger changes you may want to consider using
a local clone.
dmd.root.optional
Implementation of an 'Optional' type
Authors:
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));
- struct
Optional
(T); - Optional type that is either empty or contains a value of type T
- this(T
value
);
static Optional!Tcreate
(Tval
); - Creates an Optional with the given value
- const bool
isPresent
(); - Returns:Whether this Optional contains a value
- const bool
isEmpty
(); - Returns:Whether this Optional does not contain a value
- inout inout(T)
get
(); - Returns:The value if present
- const bool
hasValue
(const Texp
); - Returns:Whether this Optional contains the supplied value
Copyright © 1999-2024 by the D Language Foundation | Page generated by
Ddoc on (no date time)