View source code
Display the source code in std/typecons.d from which this
page was generated on github.
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
local clone.
std.typecons.Nullable.get
- multiple declarations
Function Nullable.get
Gets the value if not null. If this
is in the null state, and the optional
parameter fallback
was provided, it will be returned. Without fallback
,
calling get
with a null state is invalid.
inout ref inout(T) get() pure nothrow @property @safe;
inout auto get(U)
(
inout(U) fallback
) pure nothrow @property @safe;
Parameters
Name | Description |
---|---|
fallback | the value to return in case the Nullable is null. |
Returns
The value held internally by this Nullable
.
Example
int i = 42;
Nullable!int ni;
int x = ni .get(i);
writeln(x); // i
ni = 7;
x = ni .get(i);
writeln(x); // 7
Function Nullable.get
Gets the value. this
must not be in the null state.
This function is also called for the implicit conversion to T
.
inout ref inout(T) get() @property;
Preconditions
isNull
must be false
.
Returns
The value held internally by this Nullable
.
Example
import std .exception : assertThrown, assertNotThrown;
Nullable!(int, -1) ni;
//`get` is implicitly called. Will throw
//an error in non-release mode
assertThrown!Throwable(ni == 0);
ni = 0;
assertNotThrown!Throwable(ni == 0);
Authors
Andrei Alexandrescu, Bartosz Milewski, Don Clugston, Shin Fujishiro, Kenji Hara
License
Copyright © 1999-2022 by the D Language Foundation | Page generated by ddox.