Optional¶
| Spice | |
|---|---|
Optional<T> struct¶
Optionals in Spice are wrappers around values, that allow them to be empty. This can be used as better alternative to nil for empty values.
Constructors¶
ctor¶
| Spice | |
|---|---|
Initialize optional without a value
ctor¶
| Spice | |
|---|---|
Initialize optional with an initial value
Parameters
| Name | Type | Description |
|---|---|---|
data |
const T& |
Initial data value |
Methods¶
set¶
| Spice | |
|---|---|
Set the value of the optional
Parameters
| Name | Type | Description |
|---|---|---|
data |
const T& |
New data value |
get¶
| Spice | |
|---|---|
Get the value of the optional
Returns: T& — Data value
orElse¶
| Spice | |
|---|---|
Get the value of the optional. If the optional is not present, return the default value
Parameters
| Name | Type | Description |
|---|---|---|
defaultValue |
T& |
Returns: T& — Data value or default value
orElseGet¶
| Spice | |
|---|---|
Get the value of the optional. If the optional is not present, return the value of getFct
Parameters
| Name | Type | Description |
|---|---|---|
getFct |
f<T&>() |
Returns: T& — Data value or value of the function
clear¶
| Spice | |
|---|---|
Clears the value of the optional
isPresent¶
| Spice | |
|---|---|
Checks if a value is present at the moment
Returns: bool — Present or not
Operators¶
operator==¶
| Spice | |
|---|---|
Check if two optionals are equal, i.e. they have the same presence and equal payloads
Parameters
| Name | Type | Description |
|---|---|---|
lhs |
const Optional<T>& |
|
rhs |
const Optional<T>& |
Returns: bool — Equal or not equal
operator!=¶
| Spice | |
|---|---|
Check if two optionals are not equal
Parameters
| Name | Type | Description |
|---|---|---|
lhs |
const Optional<T>& |
|
rhs |
const Optional<T>& |
Returns: bool — Not equal or equal