llvm::FailureOr

Either a failure, or a valid value of type T.

Synopsis

Declared in <llvm/Support/LogicalResult.h>

template<typename T>
class [[nodiscard]] FailureOr;

Description

This class provides support for representing a failure result, or a valid value of type T. This allows for integrating with LogicalResult, while also providing a value on the success path.

Inherits the optional storage privately and re-exports the public std::optional interface with documentation. Boolean conversion and has_value are kept private to avoid confusion with LogicalResult.

Type Aliases

NameDescription
value_type Contained value type on the success path.

Member Functions

NameDescription
FailureOr [constructor]Constructors
operator LogicalResult Convert to LogicalResult: success when a value is present.

Using Declarations

NameDescription
and_then Chains a continuation when a value is present.
emplace Constructs a value in place on the success path.
operator* Accesses the stored value.
operator-> Accesses members of the stored value.
operator= Assigns from another optional or value.
or_else Supplies an alternate optional when unset.
reset Clears any stored value, leaving failure.
swap Swaps the contained state with another optional.
transform Transforms the stored value when present.
value Returns the stored value, or throws if unset.
value_or Returns the stored value, or a fallback when unset.

Return Value

NOTE

The return value should not be discarded.