![]() |
STX
1.0.0
|
#include <option_result.h>
Result type.Result<T, E> is a type used for returning and propagating errors. It is a class with the variants: Ok<T>, representing success and containing a value, and Err<E>, representing error and containing an error value.
Functions return Result whenever errors are expected and recoverable.
A simple function returning Result might be defined and used like so:
Result comes with some convenience methods that make working with it more succinct.
Result is a type that represents either success (Ok) or failure (Err).
Result is either in the Ok or Err state at any point in time
C++ 20 and above
Result unlike Option is a value-forwarding type. It doesn't have copy constructors of any sort. More like a unique_ptr.
Result should be seen as a return channel (for returning from functions) and not an object.
| using stx::Result< T, E >::error_type = E |
| using stx::Result< T, E >::value_type = T |
|
inline |
|
inline |
|
inline |
|
delete |
|
delete |
|
inlinenoexcept |
|
inline |
Returns res if the result is Ok, otherwise returns the Err value of itself.
Basic usage:
|
inline |
|
inlinenoexcept |
Converts from Result<T, E> & to Result<ConstRef<T>, ConstRef<E>>.
Produces a new Result, containing an immutable reference into the original, leaving the original in place.
Basic usage:
|
deletenoexcept |
|
inlinenoexcept |
|
inlinenoexcept |
|
deletenoexcept |
|
deletenoexcept |
|
inline |
Returns a copy of the result and its contents.
Basic usage:
|
inline |
Returns true if the result is an Ok<T> variant and contains the given value.
Basic usage:
|
inline |
Returns true if the result is an Err<E> variant containing the given value.
Basic usage:
|
inline |
|
inline |
|
inlinenoexcept |
|
inlinenoexcept |
Returns a const l-value reference to the contained error value. Note that no copying occurs here.
Panics if the value is an Ok
Basic usage:
|
delete |
Use unwrap_err() instead.
|
delete |
Use unwrap_err() instead.
|
inline |
|
inline |
|
inline |
|
inlinenoexcept |
Returns true if the result is Err<T>.
Basic usage:
|
inlinenoexcept |
Returns true if the result is an Ok<T> variant.
Basic usage:
|
inline |
Maps a Result<T, E> to Result<U, E> by applying the function op to the contained Ok<T> value, leaving an Err<E> value untouched.
This function can be used to compose the results of two functions.
Basic usage:
Extract the content-type from an http header
|
inline |
|
inline |
Applies a function to the contained value (if any), or returns the provided default (if not).
Basic usage:
|
inline |
Maps a Result<T, E> to U by applying a function to a contained Ok value, or a fallback function to a contained Err value.
This function can be used to unpack a successful result while handling an error.
Basic usage:
|
inline |
Calls the parameter ok_fn with the value if this result is an Ok<T>, else calls err_fn with the error. This result is consumed afterward.
The return type of both parameters must be convertible. They can also both return nothing ( void ).
Basic usage:
|
inline |
|
inline |
|
inline |
|
inlinenoexcept |
|
inline |
|
inline |
|
inline |
|
inline |
|
delete |
|
inline |
|
inline |
|
inline |
|
inline |
Returns res if the result is Err, otherwise returns the Ok value of itself.
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 |
|
inline |
|
inline |
Unwraps a result, yielding the content of an Err.
Panics if the value is an Ok, with a custom panic message provided by the Ok's value.
Basic usage:
|
inline |
Unwraps a result, yielding the content of an Ok<T> variant. Else, it returns the parameter 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
Consumes itself then, if Ok, returns the contained value, otherwise if Err, returns the default value for that type.
Basic usage:
|
inline |
Unwraps a result, yielding the content of an Ok. If the value is an Err then it calls op with its value.
Basic usage:
|
inlinenoexcept |
Returns an l-value reference to the contained value. Note that no copying occurs here.
Panics if the value is an Err
Basic usage:
|
inlinenoexcept |
Returns an l-value reference to the contained value. Note that no copying occurs here.
Panics if the value is an Err
Basic usage:
|
delete |
Use unwrap() instead.
|
delete |
Use unwrap() instead.
|
friend |
|
friend |
| E stx::Result< T, E >::storage_err_ |
| T stx::Result< T, E >::storage_value_ |