LLVM API Documentation

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Public Types | Public Member Functions | Static Public Member Functions | Friends | List of all members
llvm::ErrorOr< T > Class Template Reference

Represents either an error or a value T. More...

#include <ErrorOr.h>

Collaboration diagram for llvm::ErrorOr< T >:
Collaboration graph
[legend]

Public Types

typedef conditional< isRef,
wrap, T >::type 
storage_type
 
typedef void(* unspecified_bool_type )()
 

Public Member Functions

template<class E >
 ErrorOr (E ErrorCode, typename enable_if_c< is_error_code_enum< E >::value||is_error_condition_enum< E >::value, void * >::type=0)
 
 ErrorOr (llvm::error_code EC)
 
 ErrorOr (T Val)
 
 ErrorOr (const ErrorOr &Other)
 
template<class OtherT >
 ErrorOr (const ErrorOr< OtherT > &Other)
 
ErrorOroperator= (const ErrorOr &Other)
 
template<class OtherT >
ErrorOroperator= (const ErrorOr< OtherT > &Other)
 
 ~ErrorOr ()
 
 operator unspecified_bool_type () const
 Return false if there is an error. More...
 
 operator llvm::error_code () const
 
pointer operator-> ()
 
reference operator* ()
 

Static Public Member Functions

static void unspecified_bool_true ()
 

Friends

template<class OtherT >
class ErrorOr
 

Detailed Description

template<class T>
class llvm::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();
void handleError(error_code ec);
auto buffer = getBuffer();
if (!buffer)
handleError(buffer);
buffer->write("adena");

An implicit conversion to bool provides a way to check if there was an error. 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 behaivor 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.

Definition at line 94 of file ErrorOr.h.

Member Typedef Documentation

template<class T>
typedef conditional< isRef , wrap , T >::type llvm::ErrorOr< T >::storage_type

Definition at line 104 of file ErrorOr.h.

template<class T>
typedef void(* llvm::ErrorOr< T >::unspecified_bool_type)()

Definition at line 174 of file ErrorOr.h.

Constructor & Destructor Documentation

template<class T>
template<class E >
llvm::ErrorOr< T >::ErrorOr ( ErrorCode,
typename enable_if_c< is_error_code_enum< E >::value||is_error_condition_enum< E >::value, void * >::type  = 0 
)
inline

Definition at line 112 of file ErrorOr.h.

References llvm::make_error_code().

template<class T>
llvm::ErrorOr< T >::ErrorOr ( llvm::error_code  EC)
inline

Definition at line 119 of file ErrorOr.h.

template<class T>
llvm::ErrorOr< T >::ErrorOr ( T  Val)
inline

Definition at line 123 of file ErrorOr.h.

template<class T>
llvm::ErrorOr< T >::ErrorOr ( const ErrorOr< T > &  Other)
inline

Definition at line 127 of file ErrorOr.h.

template<class T>
template<class OtherT >
llvm::ErrorOr< T >::ErrorOr ( const ErrorOr< OtherT > &  Other)
inline

Definition at line 132 of file ErrorOr.h.

template<class T>
llvm::ErrorOr< T >::~ErrorOr ( )
inline

Definition at line 169 of file ErrorOr.h.

Member Function Documentation

template<class T>
llvm::ErrorOr< T >::operator llvm::error_code ( ) const
inline

Definition at line 182 of file ErrorOr.h.

References llvm::error_code::success().

template<class T>
llvm::ErrorOr< T >::operator unspecified_bool_type ( ) const
inline

Return false if there is an error.

Definition at line 178 of file ErrorOr.h.

References llvm::ErrorOr< T >::unspecified_bool_true().

template<class T>
reference llvm::ErrorOr< T >::operator* ( )
inline

Definition at line 190 of file ErrorOr.h.

template<class T>
pointer llvm::ErrorOr< T >::operator-> ( )
inline

Definition at line 186 of file ErrorOr.h.

template<class T>
ErrorOr& llvm::ErrorOr< T >::operator= ( const ErrorOr< T > &  Other)
inline

Definition at line 136 of file ErrorOr.h.

template<class T>
template<class OtherT >
ErrorOr& llvm::ErrorOr< T >::operator= ( const ErrorOr< OtherT > &  Other)
inline

Definition at line 142 of file ErrorOr.h.

template<class T>
static void llvm::ErrorOr< T >::unspecified_bool_true ( )
inlinestatic

Definition at line 175 of file ErrorOr.h.

Referenced by llvm::ErrorOr< T >::operator unspecified_bool_type().

Friends And Related Function Documentation

template<class T>
template<class OtherT >
friend class ErrorOr
friend

Definition at line 95 of file ErrorOr.h.

Member Data Documentation

template<class T>
AlignedCharArrayUnion<error_code> llvm::ErrorOr< T >::ErrorStorage

Definition at line 281 of file ErrorOr.h.

template<class T>
AlignedCharArrayUnion<storage_type> llvm::ErrorOr< T >::TStorage

Definition at line 280 of file ErrorOr.h.


The documentation for this class was generated from the following file: