|
| | ErrorOr (const ErrorInfo &EI) |
| |
| | ErrorOr (const ErrorOr &Other) |
| |
| template<class OtherT > |
| | ErrorOr (const ErrorOr< OtherT > &Other, std::enable_if_t< std::is_convertible< OtherT, T >::value > *=nullptr) |
| |
| template<class OtherT > |
| | ErrorOr (const ErrorOr< OtherT > &Other, std::enable_if_t<!std::is_convertible< OtherT, const T & >::value > *=nullptr) |
| |
| template<class E > |
| | ErrorOr (E ErrorCode, const std::string &Msg="", std::enable_if_t< std::is_error_code_enum< E >::value||std::is_error_condition_enum< E >::value, void * >=nullptr) |
| |
| | ErrorOr (ErrorOr &&Other) |
| |
| template<class OtherT > |
| | ErrorOr (ErrorOr< OtherT > &&Other, std::enable_if_t< std::is_convertible< OtherT, T >::value > *=nullptr) |
| |
| template<class OtherT > |
| | ErrorOr (ErrorOr< OtherT > &&Other, std::enable_if_t<!std::is_convertible< OtherT, T >::value > *=nullptr) |
| |
| template<class OtherT > |
| | ErrorOr (OtherT &&Val, std::enable_if_t< std::is_convertible< OtherT, T >::value > *=nullptr) |
| |
| | ErrorOr (std::error_code EC, const std::string &Msg="") |
| |
| | ~ErrorOr () |
| |
| reference | get () |
| |
| const_reference | get () const |
| |
| ErrorInfo | getError () const |
| |
| | operator bool () const |
| | Return false if there is an error. More...
|
| |
| reference | operator* () |
| |
| const_reference | operator* () const |
| |
| pointer | operator-> () |
| |
| const_pointer | operator-> () const |
| |
| ErrorOr & | operator= (const ErrorOr &Other) |
| |
| ErrorOr & | operator= (ErrorOr &&Other) |
| |
template<class T>
class gtirb::ErrorOr< T >
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.
ErrorOr<Buffer> getBuffer();
auto buffer = getBuffer();
if (error_code ec = buffer.getError())
return ec;
buffer->write("adena");
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.