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 inout(T) get (
  inout(T) fallback
) @property;

inout auto get(U) (
  inout(U) fallback
) @property;

When the fallback type is different from the Nullable type, get(T) returns the common type.

Parameters

NameDescription
fallback the value to return in case the Nullable is null.

Returns

The value held internally by this Nullable.

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

Boost License 1.0.