WPILibC++
2019.1.1-beta-1-15-gd03b020
|
Represents either an error or a value T. More...
#include <ErrorOr.h>
Public Types | |
using | storage_type = typename std::conditional< isRef, wrap, T >::type |
Public Member Functions | |
template<class E > | |
ErrorOr (E ErrorCode, typename std::enable_if< std::is_error_code_enum< E >::value||std::is_error_condition_enum< E >::value, void * >::type=nullptr) | |
ErrorOr (std::error_code EC) | |
template<class OtherT > | |
ErrorOr (OtherT &&Val, typename std::enable_if< std::is_convertible< OtherT, T >::value >::type *=nullptr) | |
ErrorOr (const ErrorOr &Other) | |
template<class OtherT > | |
ErrorOr (const ErrorOr< OtherT > &Other, typename std::enable_if< std::is_convertible< OtherT, T >::value >::type *=nullptr) | |
template<class OtherT > | |
ErrorOr (const ErrorOr< OtherT > &Other, typename std::enable_if< !std::is_convertible< OtherT, const T & >::value >::type *=nullptr) | |
ErrorOr (ErrorOr &&Other) | |
template<class OtherT > | |
ErrorOr (ErrorOr< OtherT > &&Other, typename std::enable_if< std::is_convertible< OtherT, T >::value >::type *=nullptr) | |
template<class OtherT > | |
ErrorOr (ErrorOr< OtherT > &&Other, typename std::enable_if<!std::is_convertible< OtherT, T >::value >::type *=nullptr) | |
ErrorOr & | operator= (const ErrorOr &Other) |
ErrorOr & | operator= (ErrorOr &&Other) |
operator bool () const | |
Return false if there is an error. | |
reference | get () |
const_reference | get () const |
std::error_code | getError () const |
pointer | operator-> () |
const_pointer | operator-> () const |
reference | operator* () |
const_reference | operator* () const |
Friends | |
template<class OtherT > | |
class | ErrorOr |
Represents either an error or a value T.
ErrorOr<T> is a pointer-like class that represents the result of an operation. The result is either an error, or a value of type T. This is designed to emulate the usage of returning a pointer where nullptr indicates failure. However instead of just knowing that the operation failed, we also have an error_code and optional user data that describes why it failed.
It is used like the following.
Implicit conversion to bool returns true if there is a usable value. The unary * and -> operators provide pointer like access to the value. Accessing the value when there is an error has undefined behavior.
When T is a reference type the behavior is slightly different. The reference is held in a std::reference_wrapper<std::remove_reference<T>::type>, and there is special handling to make operator -> work as if T was not a reference.
T cannot be a rvalue reference.