LLVM 20.0.0git
Classes | Public Types | Public Member Functions | Protected Types | Friends | List of all members
llvm::iterator_facade_base< DerivedT, IteratorCategoryT, T, DifferenceTypeT, PointerT, ReferenceT > Class Template Reference

CRTP base class which implements the entire standard iterator facade in terms of a minimal subset of the interface. More...

#include "llvm/ADT/iterator.h"

Inherited by llvm::FixedStreamArrayIterator< PSHashRecord >, llvm::MIBundleOperandIteratorBase< const MachineOperand >, llvm::MIBundleOperandIteratorBase< MachineOperand >, llvm::StringMapIterBase< StringMapConstIterator< ValueTy >, const StringMapEntry< ValueTy > >, llvm::StringMapIterBase< StringMapIterator< ValueTy >, StringMapEntry< ValueTy > >, llvm::concat_iterator< GlobalValue, iterator, global_iterator, alias_iterator, ifunc_iterator >, llvm::detail::zip_common< zip_enumerator< Iters... >, EnumeratorTupleType< Iters... >, Iters... >, llvm::detail::zip_common< zip_first< Iters... >, ZipTupleType< Iters... >::type, Iters... >, llvm::detail::zip_common< zip_shortest< Iters... >, ZipTupleType< Iters... >::type, Iters... >, llvm::indexed_accessor_iterator< iterator, BaseT, T, PointerT, ReferenceT >, llvm::iterator_adaptor_base< AACallEdgeIterator, SetVector< Function * >::iterator >, llvm::iterator_adaptor_base< IteratorImpl< ValueT, IteratorBase >, IteratorBase, std::bidirectional_iterator_tag, ValueT >, llvm::iterator_adaptor_base< const_succ_op_iterator, const_value_op_iterator, std::random_access_iterator_tag, const BasicBlock *, ptrdiff_t, const BasicBlock *, const BasicBlock * >, llvm::iterator_adaptor_base< succ_op_iterator, value_op_iterator, std::random_access_iterator_tag, BasicBlock *, ptrdiff_t, BasicBlock *, BasicBlock * >, llvm::iterator_adaptor_base< const_value_iterator, ListTy::const_iterator, std::forward_iterator_tag, const DIEValue >, llvm::iterator_adaptor_base< value_iterator, ListTy::iterator, std::forward_iterator_tag, DIEValue >, llvm::iterator_adaptor_base< const_child_iterator, const_child_iterator_base >, llvm::iterator_adaptor_base< const_toplevel_iterator, const_toplevel_iterator_base >, llvm::iterator_adaptor_base< ChildIteratorType, SmallVector< BoUpSLP::EdgeInfo, 1 >::iterator >, llvm::iterator_adaptor_base< ImutAVLValueIterator< ImmutableMap >, T::TreeTy::iterator, std::iterator_traits< T::TreeTy::iterator >::iterator_category, const T::value_type >, llvm::iterator_adaptor_base< ImutAVLValueIterator< ImmutableMapRef >, T::TreeTy::iterator, std::iterator_traits< T::TreeTy::iterator >::iterator_category, const T::value_type >, llvm::iterator_adaptor_base< ImutAVLValueIterator< T >, T::TreeTy::iterator, std::iterator_traits< T::TreeTy::iterator >::iterator_category, const T::value_type >, llvm::iterator_adaptor_base< call_iterator, VectorImplT::iterator, std::forward_iterator_tag >, llvm::iterator_adaptor_base< iterator, VectorImplT::iterator, std::forward_iterator_tag >, llvm::iterator_adaptor_base< WrappedSuccIterator, succ_iterator, std::iterator_traits< succ_iterator >::iterator_category, NodeRef, std::ptrdiff_t, NodeRef *, NodeRef >, llvm::iterator_adaptor_base< MCRegUnitIterator, MCRegisterInfo::DiffListIterator, std::forward_iterator_tag, const MCRegUnit >, llvm::iterator_adaptor_base< MCSubRegIterator, MCRegisterInfo::DiffListIterator, std::forward_iterator_tag, const MCPhysReg >, llvm::iterator_adaptor_base< MCSuperRegIterator, MCRegisterInfo::DiffListIterator, std::forward_iterator_tag, const MCPhysReg >, llvm::iterator_adaptor_base< const_symbol_iterator, SymbolsMapType::const_iterator, std::forward_iterator_tag, const Symbol *, ptrdiff_t, const Symbol *, const Symbol * >, llvm::iterator_adaptor_base< value_op_iterator, op_iterator, std::random_access_iterator_tag, SDValue, ptrdiff_t, value_op_iterator *, value_op_iterator * >, llvm::iterator_adaptor_base< StringMapKeyIterator< ValueTy >, StringMapConstIterator< ValueTy >, std::forward_iterator_tag, StringRef >, llvm::iterator_adaptor_base< const_value_op_iterator, const_op_iterator, std::random_access_iterator_tag, const Value *, ptrdiff_t, const Value *, const Value * >, llvm::iterator_adaptor_base< value_op_iterator, op_iterator, std::random_access_iterator_tag, Value *, ptrdiff_t, Value *, Value * >, llvm::iterator_adaptor_base< DbgAssignIt, Value::user_iterator, std::iterator_traits< Value::user_iterator >::iterator_category, DbgAssignIntrinsic *, std::ptrdiff_t, DbgAssignIntrinsic **, DbgAssignIntrinsic *& >, llvm::iterator_adaptor_base< early_inc_iterator_impl< WrappedIteratorT >, WrappedIteratorT, std::input_iterator_tag >, llvm::iterator_adaptor_base< filter_iterator_base< WrappedIteratorT, PredicateT, IterTag >, WrappedIteratorT, std::common_type_t< IterTag, std::iterator_traits< WrappedIteratorT >::iterator_category > >, llvm::iterator_adaptor_base< filter_iterator_base< WrappedIteratorT, PredicateT, std::forward_iterator_tag >, WrappedIteratorT, std::common_type_t< std::forward_iterator_tag, std::iterator_traits< WrappedIteratorT >::iterator_category > >, llvm::iterator_adaptor_base< filter_iterator_base< WrappedIteratorT, PredicateT, std::bidirectional_iterator_tag >, WrappedIteratorT, std::common_type_t< std::bidirectional_iterator_tag, std::iterator_traits< WrappedIteratorT >::iterator_category > >, llvm::iterator_adaptor_base< mapped_iterator< ItTy, FuncTy >, ItTy, std::iterator_traits< ItTy >::iterator_category, std::remove_reference_t< decltype(std::declval< FuncTy >()(*std::declval< ItTy >())) >, std::iterator_traits< ItTy >::difference_type, std::remove_reference_t< decltype(std::declval< FuncTy >()(*std::declval< ItTy >())) > *, decltype(std::declval< FuncTy >()(*std::declval< ItTy >())) >, llvm::iterator_adaptor_base< DerivedT, ItTy, std::iterator_traits< ItTy >::iterator_category, std::remove_reference_t< ReferenceTy >, std::iterator_traits< ItTy >::difference_type, std::remove_reference_t< ReferenceTy > *, ReferenceTy >, llvm::iterator_adaptor_base< GSIHashIterator, FixedStreamArrayIterator< PSHashRecord >, std::random_access_iterator_tag, const uint32_t >, llvm::iterator_adaptor_base< NeighborEdgeIteratorT< IsConst, IsOut >, typename NeighborSetT::const_iterator, std::iterator_traits< typename NeighborSetT::const_iterator >::iterator_category, std::conditional_t< IsConst, const EdgeValueType, EdgeValueType > >, llvm::memoryaccess_def_iterator_base< MemoryAccess >, llvm::BasicBlock::phi_iterator_impl< PHINodeT, BBIteratorT >, llvm::def_chain_iterator< T, UseOptimizedChain >, llvm::detail::zip_common< ZipType, ReferenceTupleType, Iters >, llvm::indexed_accessor_iterator< DerivedT, BaseT, T, PointerT, ReferenceT >, llvm::iterator_adaptor_base< DerivedT, WrappedIteratorT, IteratorCategoryT, T, DifferenceTypeT, PointerT, ReferenceT >, and llvm::scc_iterator< GraphT, GT >.

Classes

class  PointerProxy
 A proxy object for computing a pointer via indirecting a copy of a reference. More...
 
class  ReferenceProxy
 A proxy object for computing a reference via indirecting a copy of an iterator. More...
 

Public Types

using iterator_category = IteratorCategoryT
 
using value_type = T
 
using difference_type = DifferenceTypeT
 
using pointer = PointerT
 
using reference = ReferenceT
 

Public Member Functions

DerivedT operator+ (DifferenceTypeT n) const
 
DerivedT operator- (DifferenceTypeT n) const
 
DerivedT & operator++ ()
 
DerivedT operator++ (int)
 
DerivedT & operator-- ()
 
DerivedT operator-- (int)
 
bool operator!= (const DerivedT &RHS) const
 
bool operator> (const DerivedT &RHS) const
 
bool operator<= (const DerivedT &RHS) const
 
bool operator>= (const DerivedT &RHS) const
 
PointerProxy operator-> () const
 
ReferenceProxy operator[] (DifferenceTypeT n) const
 

Protected Types

enum  { IsRandomAccess , IsBidirectional }
 

Friends

DerivedT operator+ (DifferenceTypeT n, const DerivedT &i)
 

Detailed Description

template<typename DerivedT, typename IteratorCategoryT, typename T, typename DifferenceTypeT = std::ptrdiff_t, typename PointerT = T *, typename ReferenceT = T &>
class llvm::iterator_facade_base< DerivedT, IteratorCategoryT, T, DifferenceTypeT, PointerT, ReferenceT >

CRTP base class which implements the entire standard iterator facade in terms of a minimal subset of the interface.

Use this when it is reasonable to implement most of the iterator functionality in terms of a core subset. If you need special behavior or there are performance implications for this, you may want to override the relevant members instead.

Note, one abstraction that this does not provide is implementing subtraction in terms of addition by negating the difference. Negation isn't always information preserving, and I can see very reasonable iterator designs where this doesn't work well. It doesn't really force much added boilerplate anyways.

Another abstraction that this doesn't provide is implementing increment in terms of addition of one. These aren't equivalent for all iterator categories, and respecting that adds a lot of complexity for little gain.

Iterators are expected to have const rules analogous to pointers, with a single, const-qualified operator*() that returns ReferenceT. This matches the second and third pointers in the following example:

int Value;
{ int *I = &Value; } // ReferenceT 'int&'
{ int *const I = &Value; } // ReferenceT 'int&'; const
{ const int *I = &Value; } // ReferenceT 'const int&'
{ const int *const I = &Value; } // ReferenceT 'const int&'; const
#define I(x, y, z)
Definition: MD5.cpp:58
LLVM Value Representation.
Definition: Value.h:74

If an iterator facade returns a handle to its own state, then T (and PointerT and ReferenceT) should usually be const-qualified. Otherwise, if clients are expected to modify the handle itself, the field can be declared mutable or use const_cast.

Classes wishing to use iterator_facade_base should implement the following methods:

Forward Iterators: (All of the following methods)

Bidirectional Iterators: (All methods of forward iterators, plus the following)

Random-access Iterators: (All methods of bidirectional iterators excluding the following)

Definition at line 80 of file iterator.h.

Member Typedef Documentation

◆ difference_type

template<typename DerivedT , typename IteratorCategoryT , typename T , typename DifferenceTypeT = std::ptrdiff_t, typename PointerT = T *, typename ReferenceT = T &>
using llvm::iterator_facade_base< DerivedT, IteratorCategoryT, T, DifferenceTypeT, PointerT, ReferenceT >::difference_type = DifferenceTypeT

Definition at line 84 of file iterator.h.

◆ iterator_category

template<typename DerivedT , typename IteratorCategoryT , typename T , typename DifferenceTypeT = std::ptrdiff_t, typename PointerT = T *, typename ReferenceT = T &>
using llvm::iterator_facade_base< DerivedT, IteratorCategoryT, T, DifferenceTypeT, PointerT, ReferenceT >::iterator_category = IteratorCategoryT

Definition at line 82 of file iterator.h.

◆ pointer

template<typename DerivedT , typename IteratorCategoryT , typename T , typename DifferenceTypeT = std::ptrdiff_t, typename PointerT = T *, typename ReferenceT = T &>
using llvm::iterator_facade_base< DerivedT, IteratorCategoryT, T, DifferenceTypeT, PointerT, ReferenceT >::pointer = PointerT

Definition at line 85 of file iterator.h.

◆ reference

template<typename DerivedT , typename IteratorCategoryT , typename T , typename DifferenceTypeT = std::ptrdiff_t, typename PointerT = T *, typename ReferenceT = T &>
using llvm::iterator_facade_base< DerivedT, IteratorCategoryT, T, DifferenceTypeT, PointerT, ReferenceT >::reference = ReferenceT

Definition at line 86 of file iterator.h.

◆ value_type

template<typename DerivedT , typename IteratorCategoryT , typename T , typename DifferenceTypeT = std::ptrdiff_t, typename PointerT = T *, typename ReferenceT = T &>
using llvm::iterator_facade_base< DerivedT, IteratorCategoryT, T, DifferenceTypeT, PointerT, ReferenceT >::value_type = T

Definition at line 83 of file iterator.h.

Member Enumeration Documentation

◆ anonymous enum

template<typename DerivedT , typename IteratorCategoryT , typename T , typename DifferenceTypeT = std::ptrdiff_t, typename PointerT = T *, typename ReferenceT = T &>
anonymous enum
protected
Enumerator
IsRandomAccess 
IsBidirectional 

Definition at line 89 of file iterator.h.

Member Function Documentation

◆ operator!=()

template<typename DerivedT , typename IteratorCategoryT , typename T , typename DifferenceTypeT = std::ptrdiff_t, typename PointerT = T *, typename ReferenceT = T &>
bool llvm::iterator_facade_base< DerivedT, IteratorCategoryT, T, DifferenceTypeT, PointerT, ReferenceT >::operator!= ( const DerivedT &  RHS) const
inline

Definition at line 180 of file iterator.h.

References RHS.

◆ operator+()

template<typename DerivedT , typename IteratorCategoryT , typename T , typename DifferenceTypeT = std::ptrdiff_t, typename PointerT = T *, typename ReferenceT = T &>
DerivedT llvm::iterator_facade_base< DerivedT, IteratorCategoryT, T, DifferenceTypeT, PointerT, ReferenceT >::operator+ ( DifferenceTypeT  n) const
inline

◆ operator++() [1/2]

template<typename DerivedT , typename IteratorCategoryT , typename T , typename DifferenceTypeT = std::ptrdiff_t, typename PointerT = T *, typename ReferenceT = T &>
DerivedT & llvm::iterator_facade_base< DerivedT, IteratorCategoryT, T, DifferenceTypeT, PointerT, ReferenceT >::operator++ ( )
inline

Definition at line 154 of file iterator.h.

◆ operator++() [2/2]

template<typename DerivedT , typename IteratorCategoryT , typename T , typename DifferenceTypeT = std::ptrdiff_t, typename PointerT = T *, typename ReferenceT = T &>
DerivedT llvm::iterator_facade_base< DerivedT, IteratorCategoryT, T, DifferenceTypeT, PointerT, ReferenceT >::operator++ ( int  )
inline

Definition at line 159 of file iterator.h.

◆ operator-()

template<typename DerivedT , typename IteratorCategoryT , typename T , typename DifferenceTypeT = std::ptrdiff_t, typename PointerT = T *, typename ReferenceT = T &>
DerivedT llvm::iterator_facade_base< DerivedT, IteratorCategoryT, T, DifferenceTypeT, PointerT, ReferenceT >::operator- ( DifferenceTypeT  n) const
inline

◆ operator--() [1/2]

template<typename DerivedT , typename IteratorCategoryT , typename T , typename DifferenceTypeT = std::ptrdiff_t, typename PointerT = T *, typename ReferenceT = T &>
DerivedT & llvm::iterator_facade_base< DerivedT, IteratorCategoryT, T, DifferenceTypeT, PointerT, ReferenceT >::operator-- ( )
inline

◆ operator--() [2/2]

template<typename DerivedT , typename IteratorCategoryT , typename T , typename DifferenceTypeT = std::ptrdiff_t, typename PointerT = T *, typename ReferenceT = T &>
DerivedT llvm::iterator_facade_base< DerivedT, IteratorCategoryT, T, DifferenceTypeT, PointerT, ReferenceT >::operator-- ( int  )
inline

◆ operator->()

template<typename DerivedT , typename IteratorCategoryT , typename T , typename DifferenceTypeT = std::ptrdiff_t, typename PointerT = T *, typename ReferenceT = T &>
PointerProxy llvm::iterator_facade_base< DerivedT, IteratorCategoryT, T, DifferenceTypeT, PointerT, ReferenceT >::operator-> ( ) const
inline

Definition at line 205 of file iterator.h.

◆ operator<=()

template<typename DerivedT , typename IteratorCategoryT , typename T , typename DifferenceTypeT = std::ptrdiff_t, typename PointerT = T *, typename ReferenceT = T &>
bool llvm::iterator_facade_base< DerivedT, IteratorCategoryT, T, DifferenceTypeT, PointerT, ReferenceT >::operator<= ( const DerivedT &  RHS) const
inline

◆ operator>()

template<typename DerivedT , typename IteratorCategoryT , typename T , typename DifferenceTypeT = std::ptrdiff_t, typename PointerT = T *, typename ReferenceT = T &>
bool llvm::iterator_facade_base< DerivedT, IteratorCategoryT, T, DifferenceTypeT, PointerT, ReferenceT >::operator> ( const DerivedT &  RHS) const
inline

◆ operator>=()

template<typename DerivedT , typename IteratorCategoryT , typename T , typename DifferenceTypeT = std::ptrdiff_t, typename PointerT = T *, typename ReferenceT = T &>
bool llvm::iterator_facade_base< DerivedT, IteratorCategoryT, T, DifferenceTypeT, PointerT, ReferenceT >::operator>= ( const DerivedT &  RHS) const
inline

◆ operator[]()

template<typename DerivedT , typename IteratorCategoryT , typename T , typename DifferenceTypeT = std::ptrdiff_t, typename PointerT = T *, typename ReferenceT = T &>
ReferenceProxy llvm::iterator_facade_base< DerivedT, IteratorCategoryT, T, DifferenceTypeT, PointerT, ReferenceT >::operator[] ( DifferenceTypeT  n) const
inline

Friends And Related Function Documentation

◆ operator+

template<typename DerivedT , typename IteratorCategoryT , typename T , typename DifferenceTypeT = std::ptrdiff_t, typename PointerT = T *, typename ReferenceT = T &>
DerivedT operator+ ( DifferenceTypeT  n,
const DerivedT &  i 
)
friend

Definition at line 139 of file iterator.h.


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