![]() |
STX
1.0.0
|
#include <option_result.h>
Optional values.
Type Option
represents an optional value: every Option
is either Some
and contains a value, or None
, and does not. They have a number of uses:
None
is returned on errorOption
's are commonly paired with pattern matching to query the presence of a value and take action, always accounting for the None
s case.
C++ 20 and above
using stx::Option< T >::value_type = T |
|
inlinenoexcept |
|
inline |
|
inline |
|
inlinenoexcept |
|
inline |
|
inline |
|
inlinenoexcept |
|
inline |
Returns None
if the option is None
, otherwise returns cmp
.
Basic usage:
|
inline |
Returns None
if the option is None
, otherwise calls op
with the wrapped value and returns the result.
Some languages call this operation flatmap.
Basic usage:
|
inlinenoexcept |
|
deletenoexcept |
|
inlinenoexcept |
|
inlinenoexcept |
|
deletenoexcept |
|
deletenoexcept |
|
inline |
Returns a copy of the option and its contents.
Basic usage:
|
inline |
|
inline |
|
inline |
Unwraps an option, yielding the content of a Some
.
Panics if the value is a None
with a custom panic message provided by msg
.
Basic usage:
|
inline |
Unwraps an option, expecting None
and returning nothing.
Panics if the value is a Some
, with a panic message.
Basic usage:
|
inline |
|
inline |
Returns None
if the option is None
, otherwise calls predicate
with the wrapped value and returns:
Some<T>
if predicate
returns false
on invocation on the value.None
if predicate
returns true
on invocation on the value.filter_not()
lets you decide which elements to keep.
Basic usage:
|
inlinenoexcept |
|
inlinenoexcept |
|
inline |
Maps an Option<T>
to Option<U>
by applying a function to a contained value and therefore, consuming/moving the contained value.
Basic usage:
Converts an Option<string>
into an Option<size_t>
, consuming the original:
|
inline |
Applies a function to the contained value (if any), or returns the provided alternative (if not).
Basic usage:
|
inline |
Applies a function to the contained value (if any), or computes a default (if not).
Basic usage:
|
inline |
Calls the parameter some_fn
with the value if this Option
is a Some<T>
variant, else calls none_fn
. This Option
is consumed afterward.
The return type of both parameters must be convertible. They can also both return nothing ( void
).
Basic usage:
|
inline |
|
inline |
|
inline |
|
inline |
Transforms the Option<T>
into a Result<T, E>
, mapping Some<T>
to Ok<T>
and None
to Err(op())
.
Basic usage:
|
inlinenoexcept |
|
inline |
|
inline |
|
inlinenoexcept |
|
inline |
|
inline |
|
inline |
|
inline |
|
inlinenoexcept |
|
inline |
Returns the option if it contains a value, otherwise returns alt
.
Arguments passed to OR
are eagerly evaluated; if you are passing the result of a function call, it is recommended to use or_else
, which is lazily evaluated.
Basic usage:
|
inline |
Returns the option if it contains a value, otherwise calls f
and returns the result.
Basic usage:
|
inline |
Replaces the actual value in the option by the value given in parameter, returning the old value if present, leaving a Some
in its place without deinitializing either one.
Basic usage:
|
inline |
Replaces the actual value in the option by the value given in parameter, returning the old value if present, leaving a Some
in its place without deinitializing either one.
Basic usage:
|
inline |
|
inline |
|
inline |
Unwraps an option, expecting None
and returning nothing.
Panics if the value is a Some
.
Basic usage:
|
inline |
Returns the contained value or an alternative: alt
.
Arguments passed to unwrap_or
are eagerly evaluated; if you are passing the result of a function call, it is recommended to use unwrap_or_else
, which is lazily evaluated.
Basic usage:
|
inline |
Returns the contained value or a default of T
Consumes this object and returns its Some<T>
value if it is a Some<T>
variant, else if this object is a None
variant, returns the default of the value type T
.
Basic usage:
|
inline |
Returns the contained value or computes it from a function.
Basic usage:
|
inlinenoexcept |
Returns an l-value reference to the contained value. Note that no copying occurs here.
Panics if the value is a None
Basic usage:
|
inlinenoexcept |
Returns a const l-value reference to the contained value. Note that no copying occurs here.
Panics if the value is a None
Basic usage:
|
delete |
Use unwrap()
instead.
|
delete |
Use unwrap()
instead.
|
inline |
Returns whichever one of this object or alt
is a Some<T>
variant, otherwise returns None
if neither or both are a Some<T>
variant.
Basic usage:
|
friend |
T stx::Option< T >::storage_value_ |