class Expected

Declaration

template <class T>
class Expected { /* full declaration omitted */ };

Description

Tagged union holding either a T or a Error. This class parallels ErrorOr, but replaces error_code with Error. Since Error cannot be copied, this class replaces getError() with takeError(). It also adds an bool errorIsA <ErrT >() method for testing the error class type. Example usage of 'Expected <T >' as a function return type: Checking the results of to a function returning 'Expected <T >': For unit-testing a function returning an 'Expceted <T >', see the 'EXPECT_THAT_EXPECTED' macros in llvm/Testing/Support/Error.h

Declared at: llvm/include/llvm/Support/Error.h:469

Templates

T

Member Variables

private anonymous struct / union
private bool HasError
private static const bool isRef = std::is_reference<type-parameter-0-0>::value

Method Overview

  • public Expected<T>(llvm::ErrorSuccess)
  • public Expected<T>(Expected<T> && Other)
  • public template <class OtherT> Expected<T>(Expected<OtherT> && Other, std::enable_if_t<!std::is_convertible<OtherT, T>::value> * = nullptr)
  • public template <class OtherT> Expected<T>(Expected<OtherT> && Other, std::enable_if_t<std::is_convertible<OtherT, T>::value> * = nullptr)
  • public template <typename OtherT> Expected<T>(OtherT && Val, std::enable_if_t<std::is_convertible<OtherT, T>::value> * = nullptr)
  • public Expected<T>(llvm::Error Err)
  • private void assertIsChecked() const
  • private template <class T1, class T2>static bool compareThisIfSameType(const T1 &, const T2 &)
  • private template <class T1>static bool compareThisIfSameType(const T1 & a, const T1 & b)
  • public template <typename ErrT>bool errorIsA() const
  • public llvm::Expected::reference get()
  • public llvm::Expected::const_reference get() const
  • private const llvm::Expected::error_type * getErrorStorage() const
  • private llvm::Expected::error_type * getErrorStorage()
  • private const llvm::Expected::storage_type * getStorage() const
  • private llvm::Expected::storage_type * getStorage()
  • private template <class OtherT>void moveAssign(Expected<OtherT> && Other)
  • private template <class OtherT>void moveConstruct(Expected<OtherT> && Other)
  • public template <class OtherT>llvm::Error moveInto(OtherT & Value, std::enable_if_t<std::is_assignable<OtherT &, T &&>::value> * = nullptr) &&
  • public bool operator bool()
  • private void setUnchecked()
  • public llvm::Error takeError()
  • private llvm::Expected::const_pointer toPointer(const llvm::Expected::wrap * Val) const
  • private llvm::Expected::pointer toPointer(llvm::Expected::wrap * Val)
  • private llvm::Expected::const_pointer toPointer(llvm::Expected::const_pointer Val) const
  • private llvm::Expected::pointer toPointer(llvm::Expected::pointer Val)
  • public ~Expected<T>()

Methods

Expected<T>(llvm::ErrorSuccess)

Description

Forbid to convert from Error::success() implicitly, this avoids having Expected <T > foo() { return Error::success(); } which compiles otherwise but triggers the assertion above.

Declared at: llvm/include/llvm/Support/Error.h:505

Parameters

llvm::ErrorSuccess

Expected<T>(Expected<T>&& Other)

Description

Move construct an Expected <T > value.

Declared at: llvm/include/llvm/Support/Error.h:523

Parameters

Expected<T>&& Other

template <class OtherT>
Expected<T>(
    Expected<OtherT>&& Other,
    std::enable_if_t<
        !std::is_convertible<OtherT, T>::value>* =
        nullptr)

Description

Move construct an Expected <T > value from an Expected <OtherT >, where OtherT isn't convertible to T.

Declared at: llvm/include/llvm/Support/Error.h:537

Templates

OtherT

Parameters

Expected<OtherT>&& Other
std::enable_if_t< !std::is_convertible<OtherT, T>::value>* = nullptr

template <class OtherT>
Expected<T>(
    Expected<OtherT>&& Other,
    std::enable_if_t<
        std::is_convertible<OtherT, T>::value>* =
        nullptr)

Description

Move construct an Expected <T > value from an Expected <OtherT >, where OtherT must be convertible to T.

Declared at: llvm/include/llvm/Support/Error.h:528

Templates

OtherT

Parameters

Expected<OtherT>&& Other
std::enable_if_t< std::is_convertible<OtherT, T>::value>* = nullptr

template <typename OtherT>
Expected<T>(
    OtherT&& Val,
    std::enable_if_t<
        std::is_convertible<OtherT, T>::value>* =
        nullptr)

Description

Create an Expected <T > success value from the given OtherT value, which must be convertible to T.

Declared at: llvm/include/llvm/Support/Error.h:510

Templates

OtherT

Parameters

OtherT&& Val
std::enable_if_t< std::is_convertible<OtherT, T>::value>* = nullptr

Expected<T>(llvm::Error Err)

Description

Create an Expected <T > error value from the given Error.

Declared at: llvm/include/llvm/Support/Error.h:491

Parameters

llvm::Error Err

void assertIsChecked() const

Declared at: llvm/include/llvm/Support/Error.h:711

template <class T1, class T2>
static bool compareThisIfSameType(const T1&,
                                  const T2&)

Declared at: llvm/include/llvm/Support/Error.h:635

Templates

T1
T2

Parameters

const T1&
const T2&

template <class T1>
static bool compareThisIfSameType(const T1& a,
                                  const T1& b)

Declared at: llvm/include/llvm/Support/Error.h:630

Templates

T1

Parameters

const T1& a
const T1& b

template <typename ErrT>
bool errorIsA() const

Description

Check that this Expected <T > is an error of type ErrT.

Declared at: llvm/include/llvm/Support/Error.h:589

Templates

ErrT

llvm::Expected::reference get()

Description

Returns a reference to the stored T value.

Declared at: llvm/include/llvm/Support/Error.h:567

llvm::Expected::const_reference get() const

Description

Returns a const reference to the stored T value.

Declared at: llvm/include/llvm/Support/Error.h:573

const llvm::Expected::error_type*
getErrorStorage() const

Declared at: llvm/include/llvm/Support/Error.h:685

llvm::Expected::error_type* getErrorStorage()

Declared at: llvm/include/llvm/Support/Error.h:680

const llvm::Expected::storage_type* getStorage()
    const

Declared at: llvm/include/llvm/Support/Error.h:675

llvm::Expected::storage_type* getStorage()

Declared at: llvm/include/llvm/Support/Error.h:670

template <class OtherT>
void moveAssign(Expected<OtherT>&& Other)

Declared at: llvm/include/llvm/Support/Error.h:652

Templates

OtherT

Parameters

Expected<OtherT>&& Other

template <class OtherT>
void moveConstruct(Expected<OtherT>&& Other)

Declared at: llvm/include/llvm/Support/Error.h:639

Templates

OtherT

Parameters

Expected<OtherT>&& Other

template <class OtherT>
llvm::Error moveInto(
    OtherT& Value,
    std::enable_if_t<
        std::is_assignable<OtherT&,
                           T&&>::value>* =
        nullptr) &&

Description

Returns \a takeError() after moving the held T (if any) into \p V.

Declared at: llvm/include/llvm/Support/Error.h:580

Templates

OtherT

Parameters

OtherT& Value
std::enable_if_t< std::is_assignable<OtherT&, T&&>::value>* = nullptr

bool operator bool()

Description

Return false if there is an error.

Declared at: llvm/include/llvm/Support/Error.h:559

void setUnchecked()

Declared at: llvm/include/llvm/Support/Error.h:691

llvm::Error takeError()

Description

Take ownership of the stored error. After calling this the Expected <T > is in an indeterminate state that can only be safely destructed. No further calls (beside the destructor) should be made on the Expected <T > value.

Declared at: llvm/include/llvm/Support/Error.h:597

llvm::Expected::const_pointer toPointer(
    const llvm::Expected::wrap* Val) const

Declared at: llvm/include/llvm/Support/Error.h:668

Parameters

const llvm::Expected::wrap* Val

llvm::Expected::pointer toPointer(
    llvm::Expected::wrap* Val)

Declared at: llvm/include/llvm/Support/Error.h:666

Parameters

llvm::Expected::wrap* Val

llvm::Expected::const_pointer toPointer(
    llvm::Expected::const_pointer Val) const

Declared at: llvm/include/llvm/Support/Error.h:664

Parameters

llvm::Expected::const_pointer Val

llvm::Expected::pointer toPointer(
    llvm::Expected::pointer Val)

Declared at: llvm/include/llvm/Support/Error.h:662

Parameters

llvm::Expected::pointer Val

~Expected<T>()

Description

Destroy an Expected <T >.

Declared at: llvm/include/llvm/Support/Error.h:550