10 #ifndef LLVM_ADT_ITERATOR_H
11 #define LLVM_ADT_ITERATOR_H
35 template <
typename DerivedT,
typename IteratorCategoryT,
typename T,
36 typename DifferenceTypeT = std::ptrdiff_t,
typename PointerT =
T *,
37 typename ReferenceT =
T &>
39 :
public std::iterator<IteratorCategoryT, T, DifferenceTypeT, PointerT,
44 std::is_base_of<std::random_access_iterator_tag, IteratorCategoryT>::value,
46 std::is_base_of<std::bidirectional_iterator_tag, IteratorCategoryT>::value,
53 "The '+' operator is only defined for random access iterators.");
54 DerivedT tmp = *
static_cast<const DerivedT *
>(
this);
58 friend DerivedT
operator+(DifferenceTypeT n,
const DerivedT &i) {
61 "The '+' operator is only defined for random access iterators.");
67 "The '-' operator is only defined for random access iterators.");
68 DerivedT tmp = *
static_cast<const DerivedT *
>(
this);
74 return static_cast<DerivedT *
>(
this)->
operator+=(1);
77 DerivedT tmp = *
static_cast<DerivedT *
>(
this);
78 ++*
static_cast<DerivedT *
>(
this);
84 "The decrement operator is only defined for bidirectional iterators.");
85 return static_cast<DerivedT *
>(
this)->
operator-=(1);
90 "The decrement operator is only defined for bidirectional iterators.");
91 DerivedT tmp = *
static_cast<DerivedT *
>(
this);
92 --*
static_cast<DerivedT *
>(
this);
97 return !
static_cast<const DerivedT *
>(
this)->
operator==(RHS);
103 "Relational operators are only defined for random access iterators.");
104 return !
static_cast<const DerivedT *
>(
this)->
operator<(RHS) &&
105 !
static_cast<const DerivedT *
>(
this)->
operator==(RHS);
110 "Relational operators are only defined for random access iterators.");
111 return !
static_cast<const DerivedT *
>(
this)->
operator>(RHS);
116 "Relational operators are only defined for random access iterators.");
117 return !
static_cast<const DerivedT *
>(
this)->
operator<(RHS);
121 return &
static_cast<const DerivedT *
>(
this)->
operator*();
125 "Subscripting is only defined for random access iterators.");
126 return *
static_cast<const DerivedT *
>(
this)->
operator+(n);
136 typename DerivedT,
typename WrappedIteratorT,
137 typename IteratorCategoryT =
138 typename std::iterator_traits<WrappedIteratorT>::iterator_category,
139 typename T =
typename std::iterator_traits<WrappedIteratorT>::value_type,
140 typename DifferenceTypeT =
141 typename std::iterator_traits<WrappedIteratorT>::difference_type,
142 typename PointerT =
T *,
typename ReferenceT =
T &,
144 typename WrappedTraitsT = std::iterator_traits<WrappedIteratorT>>
147 DifferenceTypeT, PointerT, ReferenceT> {
148 typedef typename iterator_adaptor_base::iterator_facade_base BaseT;
155 template <
typename U>
158 typename std::enable_if<
159 !std::is_base_of<
typename std::remove_cv<
160 typename std::remove_reference<U>::type>::type,
163 :
I(std::forward<U &&>(u)) {}
165 const WrappedIteratorT &
wrapped()
const {
return I; }
172 BaseT::IsRandomAccess,
173 "The '+=' operator is only defined for random access iterators.");
175 return *
static_cast<DerivedT *
>(
this);
179 BaseT::IsRandomAccess,
180 "The '-=' operator is only defined for random access iterators.");
182 return *
static_cast<DerivedT *
>(
this);
184 using BaseT::operator-;
187 BaseT::IsRandomAccess,
188 "The '-' operator is only defined for random access iterators.");
194 using BaseT::operator++;
197 return *
static_cast<DerivedT *
>(
this);
199 using BaseT::operator--;
202 BaseT::IsBidirectional,
203 "The decrement operator is only defined for bidirectional iterators.");
205 return *
static_cast<DerivedT *
>(
this);
211 BaseT::IsRandomAccess,
212 "Relational operators are only defined for random access iterators.");
228 template <
typename WrappedIteratorT,
229 typename T =
typename std::remove_reference<
230 decltype(**std::declval<WrappedIteratorT>())>::type>
233 pointee_iterator<WrappedIteratorT>, WrappedIteratorT,
234 typename std::iterator_traits<WrappedIteratorT>::iterator_category,
237 template <
typename U>
DifferenceTypeT difference_type
difference_type operator-(const DerivedT &RHS) const
bool operator>(const DerivedT &RHS) const
bool operator>=(const DerivedT &RHS) const
DerivedT operator-(DifferenceTypeT n) const
DerivedT operator+(DifferenceTypeT n) const
iterator_adaptor_base()=default
bool operator==(const DerivedT &RHS) const
bool operator<=(const DerivedT &RHS) const
DerivedT & operator+=(difference_type n)
CRTP base class which implements the entire standard iterator facade in terms of a minimal subset of ...
bool operator!=(const DerivedT &RHS) const
ReferenceT operator*() const
CRTP base class for adapting an iterator to a different type.
iterator_adaptor_base(U &&u, typename std::enable_if< !std::is_base_of< typename std::remove_cv< typename std::remove_reference< U >::type >::type, DerivedT >::value, int >::type=0)
friend DerivedT operator+(DifferenceTypeT n, const DerivedT &i)
ReferenceT operator[](DifferenceTypeT n) const
An iterator type that allows iterating over the pointees via some other iterator. ...
pointee_iterator()=default
const WrappedIteratorT & wrapped() const
DerivedT & operator-=(difference_type n)
PointerT operator->() const
bool operator<(const DerivedT &RHS) const