ROSE
0.11.137.0
|
Result containing a value or an error.
#include <util/Sawyer/Result.h>
Public Types | |
using | OkValue = T |
using | ErrorValue = E |
using | OkType = Ok< T > |
using | ErrorType = Error< E > |
Public Member Functions | |
template<class U = T> | |
Result (const Ok< U > &ok) | |
template<class F = E> | |
Result (const Error< F > &error) | |
template<class U = T> | |
Result & | operator= (const Ok< U > &ok) |
Assign an Ok value to this result. More... | |
template<class F = E> | |
Result & | operator= (const Error< F > &error) |
Assign an Error value to this result. More... | |
template<class U = T> | |
bool | operator== (const Ok< U > &ok) const |
Test whether this result has the specified Ok value. More... | |
template<class U = T> | |
bool | operator!= (const Ok< U > &ok) const |
Test whether this result does not have the specified Ok value. More... | |
template<class F = E> | |
bool | operator== (const Error< F > &error) const |
Test whether this result has the specified Error value. More... | |
template<class F = E> | |
bool | operator!= (const Error< F > &error) const |
Test whether this result does not have the specified Error value. More... | |
template<class U , class F > | |
bool | operator== (const Result< U, F > &other) const |
Test whether this result is equal to the other result. More... | |
template<class U , class F > | |
bool | operator!= (const Result< U, F > &other) const |
Test whether this result is unequal to the other result. More... | |
bool | isError () const |
Returns true if the result is an error. More... | |
const Sawyer::Optional< T > | ok () const |
Convert to Optional<T>. More... | |
const Sawyer::Optional< E > | error () const |
Convert to Optional<E>. More... | |
const T & | expect (const std::string &mesg) const |
Returns the success value or throws an exception. More... | |
const T | orElse (const T &dflt) const |
Returns the contained Ok value or a provided default. More... | |
template<class Fn > | |
std::enable_if< is_invocable< Fn, ErrorValue >::value, const Result >::type | orElse (Fn fn) const |
Returns the contained Ok value, or calls a function. More... | |
template<class F > | |
const Result< T, F > | orElse (const Result< T, F > &other) const |
Returns this value or the other result. More... | |
const T & | orDefault () const |
Returns the okay value or a default constructed value. More... | |
template<class Exception = E> | |
const T & | orThrow () const |
Returns the value or throws an exception. More... | |
template<class Exception = E> | |
const T & | orThrow (const Exception &e) const |
Returns the value or throws an exception constructed from the specified value. More... | |
template<class Fn > | |
std::enable_if< is_invocable< Fn, OkValue >::value, const Result >::type | andThen (Fn fn) const |
Returns the contained Error value, or calls a function. More... | |
template<class U > | |
const Result< U, E > | andThen (const Result< U, E > &other) const |
Returns this error or the other result. More... | |
const E & | expectError (const std::string &mesg) const |
Returns the error value or throws an exception. More... | |
const E & | unwrapError () const |
Returns the error value or throws an exception. More... | |
template<class U > | |
bool | contains (const U &value) const |
Returns true if this result contains the specified okay value. More... | |
template<class F > | |
bool | containsError (const F &error) const |
Returns true if this result contains the specified error value. More... | |
template<class U > | |
bool | assignTo (U &out) const |
Conditionally save a value. More... | |
bool | isOk () const |
Returns true if the result is okay. | |
operator bool () const | |
Returns true if the result is okay. | |
const T & | unwrap () const |
Returns the success value or throws an exception. More... | |
const T & | operator* () const |
Returns the success value or throws an exception. More... | |
|
inline |
|
inline |
|
inline |
Test whether this result has the specified Ok value.
Definition at line 335 of file Result.h.
References Sawyer::Result< T, E >::isOk(), and Sawyer::Result< T, E >::ok().
|
inline |
Test whether this result does not have the specified Ok value.
Definition at line 341 of file Result.h.
References Sawyer::Result< T, E >::ok().
|
inline |
Test whether this result has the specified Error value.
Definition at line 347 of file Result.h.
References Sawyer::Result< T, E >::error(), and Sawyer::Result< T, E >::isError().
|
inline |
Test whether this result does not have the specified Error value.
Definition at line 353 of file Result.h.
References Sawyer::Result< T, E >::error().
|
inline |
Test whether this result is equal to the other result.
Definition at line 359 of file Result.h.
References Sawyer::Result< T, E >::error(), Sawyer::Result< T, E >::isError(), Sawyer::Result< T, E >::isOk(), and Sawyer::Result< T, E >::ok().
|
inline |
|
inline |
Returns true if the result is an error.
Definition at line 382 of file Result.h.
References Sawyer::Result< T, E >::isOk().
Referenced by Sawyer::Result< T, E >::operator==().
|
inline |
Convert to Optional<T>.
If this result is okay, then return the result, otherwise return nothing.
Definition at line 389 of file Result.h.
References Sawyer::Result< T, E >::isOk().
Referenced by Sawyer::Result< T, E >::andThen(), Sawyer::Result< T, E >::operator!=(), and Sawyer::Result< T, E >::operator==().
|
inline |
Convert to Optional<E>.
If this result is an error, then return the error, otherwise return nothing.
Definition at line 400 of file Result.h.
References Sawyer::Result< T, E >::isOk().
Referenced by Sawyer::Result< T, E >::containsError(), Sawyer::Result< T, E >::operator!=(), Sawyer::Result< T, E >::operator==(), Sawyer::Result< T, E >::orElse(), and Sawyer::Result< T, E >::orThrow().
|
inline |
Returns the success value or throws an exception.
If this result is okay, then returns its value, otherwise throws an std::runtime_error
with the specified string.
Definition at line 411 of file Result.h.
References Sawyer::Result< T, E >::isOk().
Referenced by Sawyer::Result< T, E >::unwrap().
|
inline |
Returns the success value or throws an exception.
If this result is okay, then returns its value, otherwise throws an std::runtime_error
.
Definition at line 424 of file Result.h.
References Sawyer::Result< T, E >::expect().
Referenced by Sawyer::Result< T, E >::assignTo(), Sawyer::Result< T, E >::contains(), Sawyer::Result< T, E >::operator*(), Sawyer::Result< T, E >::orDefault(), Sawyer::Result< T, E >::orElse(), and Sawyer::Result< T, E >::orThrow().
|
inline |
Returns the success value or throws an exception.
If this result is okay, then returns its value, otherwise throws an std::runtime_error
.
Definition at line 427 of file Result.h.
References Sawyer::Result< T, E >::unwrap().
|
inline |
Returns the contained Ok value or a provided default.
Definition at line 433 of file Result.h.
References Sawyer::Result< T, E >::isOk(), and Sawyer::Result< T, E >::unwrap().
|
inline |
Returns the contained Ok value, or calls a function.
If this result is okay, then returns this result, otherwise calls the specified function, fn
, with this result's Error value and returns the function's result.
Definition at line 443 of file Result.h.
References Sawyer::Result< T, E >::error(), and Sawyer::Result< T, E >::isOk().
|
inline |
Returns this value or the other result.
If this result is okay then return it, otherwise returns the other
result.
Definition at line 455 of file Result.h.
References Sawyer::Result< T, E >::isOk().
|
inline |
Returns the okay value or a default constructed value.
Definition at line 464 of file Result.h.
References Sawyer::Result< T, E >::isOk(), and Sawyer::Result< T, E >::unwrap().
|
inline |
Returns the value or throws an exception.
If the result is okay, then its value is returned, otherwise either the error is thrown or it is used to construct the specified Exception
which is then thrown.
Definition at line 474 of file Result.h.
References Sawyer::Result< T, E >::error(), Sawyer::Result< T, E >::isOk(), and Sawyer::Result< T, E >::unwrap().
|
inline |
Returns the value or throws an exception constructed from the specified value.
Definition at line 484 of file Result.h.
References Sawyer::Result< T, E >::isOk(), and Sawyer::Result< T, E >::unwrap().
|
inline |
Returns the contained Error value, or calls a function.
If this result is an error, then it's returned. Otherwise the okay value is passed to the specified function and that function's return value is returned.
Definition at line 498 of file Result.h.
References Sawyer::Result< T, E >::isOk(), and Sawyer::Result< T, E >::ok().
|
inline |
Returns this error or the other result.
If this result is okay, then returns other
. Otherwise returns the error value of this result.
Definition at line 510 of file Result.h.
References Sawyer::Result< T, E >::isOk().
|
inline |
Returns the error value or throws an exception.
If this result is an error, then returns the error, otherwise throws an std::runtime_error
with the specified string.
Definition at line 521 of file Result.h.
References Sawyer::Result< T, E >::isOk().
Referenced by Sawyer::Result< T, E >::unwrapError().
|
inline |
Returns the error value or throws an exception.
If this result is an error, then returns the error, otherwise throws an std::runtime_error
.
Definition at line 532 of file Result.h.
References Sawyer::Result< T, E >::expectError().
Referenced by Sawyer::Result< T, E >::containsError().
|
inline |
Returns true if this result contains the specified okay value.
Definition at line 538 of file Result.h.
References Sawyer::Result< T, E >::isOk(), and Sawyer::Result< T, E >::unwrap().
|
inline |
Returns true if this result contains the specified error value.
Definition at line 544 of file Result.h.
References Sawyer::Result< T, E >::error(), Sawyer::Result< T, E >::isOk(), and Sawyer::Result< T, E >::unwrapError().
|
inline |
Conditionally save a value.
If this result has a value, then assign it to the argument and return true, otherwise do nothing and return false.
Definition at line 585 of file Result.h.
References Sawyer::Result< T, E >::isOk(), and Sawyer::Result< T, E >::unwrap().