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 datum
is passed, then datum
is returned, otherwise
the function will throw an AssertError
.
This function is also called for the implicit conversion to T
.
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
import core .exception : AssertError;
import std .exception : assertThrown, assertNotThrown;
Nullable!int ni;
int i = 42;
//`get` is implicitly called. Will throw
//an AssertError in non-release mode
assertThrown!AssertError(i = ni);
writeln(i); // 42
ni = 5;
assertNotThrown!AssertError(i = ni);
writeln(i); // 5
Example
int i = 42;
Nullable!int ni2;
int x = ni2 .get(i);
writeln(x); // i
ni2 = 7;
x = ni2 .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;
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-2018 by the D Language Foundation | Page generated by ddox.