View source code
Display the source code in dmd/root/optional.d from which thispage was generated on github.
Report a bug
If you spot a problem with this page, click here to create aBugzilla 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 usinglocal clone.
Module dmd.root.optional
Implementation of an 'Optional' type
Documentation
https://dlang.org/phobos/dmd_root_optional.html
Coverage
https://codecov.io/gh/dlang/dmd/src/master/src/dmd/root/optional.d
Example
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());
writeln(opt .get()); // 1
assert( opt .hasValue(1));
assert(!opt .hasValue(2));
Structs
Name | Description |
---|---|
Optional
|
Optional type that is either empty or contains a value of type T
|
Authors
License
Copyright © 1999-2025 by the D Language Foundation | Page generated by ddox.