class fallible_iterator
Declaration
template <typename Underlying>
class fallible_iterator { /* full declaration omitted */ };
Description
A wrapper class for fallible iterators. The fallible_iterator template wraps an underlying iterator-like class whose increment and decrement operations are replaced with fallible versions like: It produces an interface that is (mostly) compatible with a traditional c++ iterator, including ++ and -- operators that do not fail. Instances of the wrapper are constructed with an instance of the underlying iterator and (for non-end iterators) a reference to an Error instance. If the underlying increment/decrement operations fail, the Error is returned via this reference, and the resulting iterator value set to an end-of-range sentinel value. This enables the following loop idiom: The wrapper marks the referenced Error as unchecked after each increment and/or decrement operation, and clears the unchecked flag when a non-end value is compared against end (since, by the increment invariant, not being an end value proves that there was no error, and is equivalent to checking that the Error is success). This allows early exits from the loop body without requiring redundant error checks.
Declared at: llvm/include/llvm/ADT/fallible_iterator.h:68
Templates
- Underlying
Member Variables
- private Underlying I
- private PointerIntPair<llvm::Error*, 1> ErrState
Method Overview
- public static fallible_iterator<Underlying> end(Underlying I)
- private fallible_iterator<Underlying>(Underlying I, llvm::Error * Err)
- private llvm::Error * getErrPtr() const
- private void handleError(llvm::Error Err)
- private bool isEnd() const
- private bool isValid() const
- public static fallible_iterator<Underlying> itr(Underlying I, llvm::Error & Err)
- private void resetCheckedFlag()
Methods
¶static fallible_iterator<Underlying> end(
Underlying I)
static fallible_iterator<Underlying> end(
Underlying I)
Description
Construct a fallible iterator that can be used as an end-of-range value. A value created by this method can be dereferenced (if the underlying value points at a valid value) and compared, but not incremented or decremented.
Declared at: llvm/include/llvm/ADT/fallible_iterator.h:94
Parameters
- Underlying I
¶fallible_iterator<Underlying>(Underlying I,
llvm::Error* Err)
fallible_iterator<Underlying>(Underlying I,
llvm::Error* Err)
Declared at: llvm/include/llvm/ADT/fallible_iterator.h:195
Parameters
- Underlying I
- llvm::Error* Err
¶llvm::Error* getErrPtr() const
llvm::Error* getErrPtr() const
Declared at: llvm/include/llvm/ADT/fallible_iterator.h:198
¶void handleError(llvm::Error Err)
void handleError(llvm::Error Err)
Declared at: llvm/include/llvm/ADT/fallible_iterator.h:204
Parameters
- llvm::Error Err
¶bool isEnd() const
bool isEnd() const
Declared at: llvm/include/llvm/ADT/fallible_iterator.h:200
¶bool isValid() const
bool isValid() const
Declared at: llvm/include/llvm/ADT/fallible_iterator.h:202
¶static fallible_iterator<Underlying> itr(
Underlying I,
llvm::Error& Err)
static fallible_iterator<Underlying> itr(
Underlying I,
llvm::Error& Err)
Description
Construct a fallible iterator that *cannot* be used as an end-of-range value. A value created by this method can be dereferenced, incremented, decremented and compared, providing the underlying type supports it. The error that is passed in will be initially marked as checked, so if the iterator is not used at all the Error need not be checked.
Declared at: llvm/include/llvm/ADT/fallible_iterator.h:84
Parameters
- Underlying I
- llvm::Error& Err
¶void resetCheckedFlag()
void resetCheckedFlag()
Declared at: llvm/include/llvm/ADT/fallible_iterator.h:210