Represents either an error or a value T.
Declared in <llvm/Support/ErrorOr.h>
template<class T>
class ErrorOr;
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.
| Name | Description |
|---|---|
storage_type | Storage type for either a value or an error code. |
| Name | Description |
|---|---|
ErrorOr [constructor] | Constructors |
~ErrorOr [destructor] | Destroy the contained value or error code. |
operator= | Assignment operators |
get | get overloads |
getError | Return the stored error code, or a default-constructed code on success. |
operator* | Dereference operators |
operator-> | Member access operators |
operator bool | Return false if there is an error. |
| Name | Description |
|---|---|
ErrorStorage [variant member] | Storage for the error code on failure. |
TStorage [variant member] | Storage for the successful value. |
| Name | Description |
|---|---|
llvm::ErrorOr | Represents either an error or a value T. |
| Name | Description |
|---|---|
errorOrToExpected | Convert an ErrorOr<T> to an Expected<T>. |
expectedToErrorOr | Convert an Expected<T> to an ErrorOr<T>. |
expectedToErrorOrAndEmitErrors | Convert Val to ErrorOr, emitting diagnostics into Ctx on failure. |
needConversion | Query whether a file needs conversion to the UTF-8 codepage. |
operator== | Return true if Err holds error-code enum Code. |
sys::findProgramByName | Find the first executable file Name in Paths. |
sys::fs::disk_space | Get disk space usage information. |
sys::fs::getPermissions | Get file permissions. |
sys::fs::md5_contents | Compute an MD5 hash of the file at Path. |
sys::fs::md5_contents | Compute an MD5 hash of a file's contents. |