LLVM  4.0.0
Public Types | Public Member Functions | Friends | List of all members
llvm::Expected< T > Class Template Reference

Tagged union holding either a T or a Error. More...

#include <Error.h>

Collaboration diagram for llvm::Expected< T >:
[legend]

Public Types

typedef std::conditional
< isRef, wrap, T >::type 
storage_type
 
typedef T value_type
 

Public Member Functions

 Expected (Error Err)
 Create an Expected<T> error value from the given Error. More...
 
 Expected (ErrorSuccess)=delete
 Forbid to convert from Error::success() implicitly, this avoids having Expected<T> foo() { return Error::success(); } which compiles otherwise but triggers the assertion above. More...
 
template<typename OtherT >
 Expected (OtherT &&Val, typename std::enable_if< std::is_convertible< OtherT, T >::value >::type *=nullptr)
 Create an Expected<T> success value from the given OtherT value, which must be convertible to T. More...
 
 Expected (Expected &&Other)
 Move construct an Expected<T> value. More...
 
template<class OtherT >
 Expected (Expected< OtherT > &&Other, typename std::enable_if< std::is_convertible< OtherT, T >::value >::type *=nullptr)
 Move construct an Expected<T> value from an Expected<OtherT>, where OtherT must be convertible to T. More...
 
template<class OtherT >
 Expected (Expected< OtherT > &&Other, typename std::enable_if<!std::is_convertible< OtherT, T >::value >::type *=nullptr)
 Move construct an Expected<T> value from an Expected<OtherT>, where OtherT isn't convertible to T. More...
 
Expectedoperator= (Expected &&Other)
 Move-assign from another Expected<T>. More...
 
 ~Expected ()
 Destroy an Expected<T>. More...
 
 operator bool ()
 Return false if there is an error. More...
 
reference get ()
 Returns a reference to the stored T value. More...
 
const_reference get () const
 Returns a const reference to the stored T value. More...
 
template<typename ErrT >
bool errorIsA () const
 Check that this Expected<T> is an error of type ErrT. More...
 
Error takeError ()
 Take ownership of the stored error. More...
 
pointer operator-> ()
 Returns a pointer to the stored T value. More...
 
const_pointer operator-> () const
 Returns a const pointer to the stored T value. More...
 
reference operator* ()
 Returns a reference to the stored T value. More...
 
const_reference operator* () const
 Returns a const reference to the stored T value. More...
 

Friends

template<class OtherT >
class Expected
 

Detailed Description

template<class T>
class llvm::Expected< T >

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.

Definition at line 631 of file Support/Error.h.

Member Typedef Documentation

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

Definition at line 639 of file Support/Error.h.

template<class T>
typedef T llvm::Expected< T >::value_type

Definition at line 640 of file Support/Error.h.

Constructor & Destructor Documentation

template<class T>
llvm::Expected< T >::Expected ( Error  Err)
inline

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

Definition at line 650 of file Support/Error.h.

References assert().

template<class T>
llvm::Expected< T >::Expected ( ErrorSuccess  )
delete

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

template<class T>
template<typename OtherT >
llvm::Expected< T >::Expected ( OtherT &&  Val,
typename std::enable_if< std::is_convertible< OtherT, T >::value >::type *  = nullptr 
)
inline

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

Definition at line 669 of file Support/Error.h.

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

Move construct an Expected<T> value.

Definition at line 682 of file Support/Error.h.

References Other.

template<class T>
template<class OtherT >
llvm::Expected< T >::Expected ( Expected< OtherT > &&  Other,
typename std::enable_if< std::is_convertible< OtherT, T >::value >::type *  = nullptr 
)
inline

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

Definition at line 687 of file Support/Error.h.

References Other.

template<class T>
template<class OtherT >
llvm::Expected< T >::Expected ( Expected< OtherT > &&  Other,
typename std::enable_if<!std::is_convertible< OtherT, T >::value >::type *  = nullptr 
)
inlineexplicit

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

Definition at line 696 of file Support/Error.h.

References Other.

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

Destroy an Expected<T>.

Definition at line 710 of file Support/Error.h.

Member Function Documentation

template<class T>
template<typename ErrT >
bool llvm::Expected< T >::errorIsA ( ) const
inline

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

Definition at line 739 of file Support/Error.h.

template<class T>
reference llvm::Expected< T >::get ( )
inline
template<class T>
const_reference llvm::Expected< T >::get ( ) const
inline

Returns a const reference to the stored T value.

Definition at line 733 of file Support/Error.h.

template<class T>
llvm::Expected< T >::operator bool ( )
inlineexplicit

Return false if there is an error.

Definition at line 719 of file Support/Error.h.

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

Returns a reference to the stored T value.

Definition at line 767 of file Support/Error.h.

template<class T>
const_reference llvm::Expected< T >::operator* ( ) const
inline

Returns a const reference to the stored T value.

Definition at line 773 of file Support/Error.h.

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

Returns a pointer to the stored T value.

Definition at line 755 of file Support/Error.h.

template<class T>
const_pointer llvm::Expected< T >::operator-> ( ) const
inline

Returns a const pointer to the stored T value.

Definition at line 761 of file Support/Error.h.

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

Move-assign from another Expected<T>.

Definition at line 704 of file Support/Error.h.

References Other.

template<class T>
Error llvm::Expected< T >::takeError ( )
inline

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> vaule.

Definition at line 747 of file Support/Error.h.

References llvm::lltok::Error, and llvm::Error::success().

Referenced by llvm::object::Archive::Archive(), llvm::object::ArchiveMemberHeader::ArchiveMemberHeader(), llvm::lto::backend(), llvm::object::Archive::Child::Child(), llvm::orc::rpc::detail::ResultTraits< RetT >::consumeAbandoned(), llvm::object::SectionRef::containsSymbol(), llvm::GlobPattern::create(), llvm::object::IRObjectFile::create(), llvm::lto::InputFile::create(), llvm::object::createBinary(), doImportingForModule(), llvm::coverage::CounterMappingContext::dump(), llvm::DWARFContextInMemory::DWARFContextInMemory(), llvm::expectedToErrorOrAndEmitErrors(), llvm::object::IRObjectFile::findBitcodeInMemBuffer(), llvm::object::ModuleSummaryIndexObjectFile::findBitcodeInMemBuffer(), llvm::MCJIT::findSymbol(), llvm::MCJIT::generateCodeForModule(), llvm::object::Archive::Child::getAsBinary(), llvm::getBitcodeModuleList(), llvm::getBitcodeProducerString(), llvm::getBitcodeTargetTriple(), llvm::object::Archive::Child::getBuffer(), llvm::object::Archive::Child::getFullName(), llvm::IndexedInstrProfReader::getFunctionCounts(), llvm::getLazyBitcodeModule(), getLazyIRModule(), llvm::object::Archive::Child::getMemoryBufferRef(), llvm::getModuleSummaryIndex(), llvm::getModuleSummaryIndexForFile(), llvm::object::ArchiveMemberHeader::getName(), llvm::object::Archive::Child::getName(), llvm::object::Archive::Child::getNext(), llvm::getOffset(), llvm::NewArchiveMember::getOldMember(), getSingleModule(), llvm::object::Archive::Child::getSize(), llvm::object::MachOObjectFile::getSymbolType(), llvm::hasGlobalValueSummary(), llvm::isBitcodeContainingObjCCategory(), llvm::LTOModule::isThinLTO(), llvm::isThumbFunc(), llvm::libDriverMain(), llvm::ThinLTOCodeGenerator::linkCombinedIndex(), LLVMCreateObjectFile(), LLVMGetBitcodeModuleInContext(), LLVMGetSymbolAddress(), LLVMGetSymbolName(), LLVMMoveToContainingSection(), LLVMParseBitcodeInContext(), llvm::orc::SimpleCompiler::operator()(), llvm::parseBitcodeFile(), llvm::parseIR(), llvm::object::ObjectFile::printSymbolName(), llvm::RuntimeDyldCOFFI386::processRelocationRef(), llvm::RuntimeDyldCOFFThumb::processRelocationRef(), llvm::RuntimeDyldCOFFX86_64::processRelocationRef(), llvm::RuntimeDyldELF::processRelocationRef(), llvm::InstrProfLookupTrait::readValueProfilingData(), llvm::orc::rpc::detail::respond(), scan(), llvm::lto::thinBackend(), and writeSymbolTable().

Friends And Related Function Documentation

template<class T>
template<class OtherT >
friend class Expected
friend

Definition at line 632 of file Support/Error.h.

Member Data Documentation

template<class T>
AlignedCharArrayUnion<error_type> llvm::Expected< T >::ErrorStorage

Definition at line 853 of file Support/Error.h.

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

Definition at line 852 of file Support/Error.h.


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