Struct Option
Option is a type that contains an optional value.
Constructors
Name | Description |
this
(value)
|
Constructs a new option with value.
|
Properties
Name | Type | Description |
get [get]
|
inout(T) | Returns the encapsulated value.
|
get_ [get]
|
inout(T) | Returns the encapsulated value.
|
isNothing [get]
|
bool | Tells if the option is just a value or nothing.
|
or [set]
|
U | Returns the encapsulated value if available or a default value
otherwise.
|
Methods
Name | Description |
opAssign
(that)
|
Assigns a new value.
|
opCast
()
|
Casts this Option to bool.
|
opEquals
(that)
|
Compares this Option with that.
|
reset
()
|
Resets this Option and destroys the contained value.
|
toHash
()
|
If T has a toHash() method, Option defines
toHash() which returns T.toHash() if it is set or 0 otherwise.
|
Parameters
Name | Description |
T | Type of the encapsulated value. |
Example
Option!int option;
assert(option.isNothing);
assert(option.or(8) == 8);
option = 5;
assert(!option.isNothing);
assert(option.get == 5);
assert(option.or(8) == 5);
option.reset();
assert(option.isNothing);