9 #ifndef LLVM_ADT_ITERATOR_H 10 #define LLVM_ADT_ITERATOR_H 16 #include <type_traits> 64 template <
typename DerivedT,
typename IteratorCategoryT,
typename T,
65 typename DifferenceTypeT = std::ptrdiff_t,
typename PointerT = T *,
66 typename ReferenceT = T &>
68 :
public std::iterator<IteratorCategoryT, T, DifferenceTypeT, PointerT,
73 IteratorCategoryT>::value,
75 IteratorCategoryT>::value,
91 operator ReferenceT()
const {
return *I; }
96 static_assert(std::is_base_of<iterator_facade_base, DerivedT>::value,
97 "Must pass the derived type to this template!");
100 "The '+' operator is only defined for random access iterators.");
101 DerivedT tmp = *
static_cast<const DerivedT *
>(
this);
105 friend DerivedT
operator+(DifferenceTypeT n,
const DerivedT &i) {
108 "The '+' operator is only defined for random access iterators.");
114 "The '-' operator is only defined for random access iterators.");
115 DerivedT tmp = *
static_cast<const DerivedT *
>(
this);
121 static_assert(std::is_base_of<iterator_facade_base, DerivedT>::value,
122 "Must pass the derived type to this template!");
123 return static_cast<DerivedT *
>(
this)->
operator+=(1);
126 DerivedT tmp = *
static_cast<DerivedT *
>(
this);
127 ++*
static_cast<DerivedT *
>(
this);
133 "The decrement operator is only defined for bidirectional iterators.");
134 return static_cast<DerivedT *
>(
this)->
operator-=(1);
139 "The decrement operator is only defined for bidirectional iterators.");
140 DerivedT tmp = *
static_cast<DerivedT *
>(
this);
141 --*
static_cast<DerivedT *
>(
this);
146 return !
static_cast<const DerivedT *
>(
this)->
operator==(RHS);
152 "Relational operators are only defined for random access iterators.");
153 return !
static_cast<const DerivedT *
>(
this)->
operator<(RHS) &&
154 !
static_cast<const DerivedT *
>(
this)->
operator==(RHS);
159 "Relational operators are only defined for random access iterators.");
160 return !
static_cast<const DerivedT *
>(
this)->
operator>(RHS);
165 "Relational operators are only defined for random access iterators.");
166 return !
static_cast<const DerivedT *
>(
this)->
operator<(RHS);
169 PointerT
operator->() {
return &
static_cast<DerivedT *
>(
this)->
operator*(); }
171 return &
static_cast<const DerivedT *
>(
this)->
operator*();
175 "Subscripting is only defined for random access iterators.");
176 return ReferenceProxy(static_cast<DerivedT *>(
this)->
operator+(n));
180 "Subscripting is only defined for random access iterators.");
181 return ReferenceProxy(static_cast<const DerivedT *>(
this)->
operator+(n));
191 typename DerivedT,
typename WrappedIteratorT,
192 typename IteratorCategoryT =
193 typename std::iterator_traits<WrappedIteratorT>::iterator_category,
194 typename T =
typename std::iterator_traits<WrappedIteratorT>::value_type,
195 typename DifferenceTypeT =
196 typename std::iterator_traits<WrappedIteratorT>::difference_type,
197 typename PointerT =
typename std::conditional<
198 std::is_same<
T,
typename std::iterator_traits<
199 WrappedIteratorT>::value_type>::value,
200 typename std::iterator_traits<WrappedIteratorT>::pointer, T *>
::type,
201 typename ReferenceT =
typename std::conditional<
202 std::is_same<
T,
typename std::iterator_traits<
203 WrappedIteratorT>::value_type>::value,
204 typename std::iterator_traits<WrappedIteratorT>::reference, T &>::type>
207 DifferenceTypeT, PointerT, ReferenceT> {
208 using BaseT =
typename iterator_adaptor_base::iterator_facade_base;
216 static_assert(std::is_base_of<iterator_adaptor_base, DerivedT>::value,
217 "Must pass the derived type to this template!");
220 const WrappedIteratorT &
wrapped()
const {
return I; }
227 BaseT::IsRandomAccess,
228 "The '+=' operator is only defined for random access iterators.");
230 return *
static_cast<DerivedT *
>(
this);
234 BaseT::IsRandomAccess,
235 "The '-=' operator is only defined for random access iterators.");
237 return *
static_cast<DerivedT *
>(
this);
239 using BaseT::operator-;
242 BaseT::IsRandomAccess,
243 "The '-' operator is only defined for random access iterators.");
249 using BaseT::operator++;
252 return *
static_cast<DerivedT *
>(
this);
254 using BaseT::operator--;
257 BaseT::IsBidirectional,
258 "The decrement operator is only defined for bidirectional iterators.");
260 return *
static_cast<DerivedT *
>(
this);
263 bool operator==(
const DerivedT &RHS)
const {
return I == RHS.I; }
266 BaseT::IsRandomAccess,
267 "Relational operators are only defined for random access iterators.");
283 template <
typename WrappedIteratorT,
284 typename T =
typename std::remove_reference<
285 decltype(**std::declval<WrappedIteratorT>())>::type>
288 pointee_iterator<WrappedIteratorT, T>, WrappedIteratorT,
289 typename std::iterator_traits<WrappedIteratorT>::iterator_category,
292 template <
typename U>
299 template <
typename RangeT,
typename WrappedIteratorT =
305 PointeeIteratorT(
std::end(std::forward<RangeT>(Range))));
308 template <
typename WrappedIteratorT,
309 typename T = decltype(&*std::declval<WrappedIteratorT>())>
312 pointer_iterator<WrappedIteratorT, T>, WrappedIteratorT,
313 typename std::iterator_traits<WrappedIteratorT>::iterator_category,
327 template <
typename RangeT,
typename WrappedIteratorT =
333 PointerIteratorT(
std::end(std::forward<RangeT>(Range))));
336 template <
typename WrappedIteratorT,
337 typename T1 =
typename std::remove_reference<decltype(**std::declval<WrappedIteratorT>())>::type,
338 typename T2 =
typename std::add_pointer<T1>::type>
343 template <
typename ItType,
typename NodeRef,
typename DataRef>
346 WrappedPairNodeDataIterator<ItType, NodeRef, DataRef>, ItType,
347 typename std::iterator_traits<ItType>::iterator_category, NodeRef,
348 std::ptrdiff_t, NodeRef *, NodeRef &> {
351 typename std::iterator_traits<ItType>::iterator_category, NodeRef,
352 std::ptrdiff_t, NodeRef *, NodeRef &>;
359 :
BaseT(Begin), DR(DR) {
364 NR.second = *this->
I;
371 #endif // LLVM_ADT_ITERATOR_H const_iterator end(StringRef path)
Get end iterator over path.
DerivedT operator-(DifferenceTypeT n) const
const_iterator begin(StringRef path, Style style=Style::native)
Get begin iterator over path.
bool operator==(const DerivedT &RHS) const
This class represents lattice values for constants.
bool operator!=(const DerivedT &RHS) const
ReferenceT operator*() const
bool operator>=(const DerivedT &RHS) const
This provides a very simple, boring adaptor for a begin and end iterator into a range type...
bool operator<=(const DerivedT &RHS) const
A proxy object for computing a reference via indirecting a copy of an iterator.
DerivedT & operator-=(difference_type n)
bool operator<(const DerivedT &RHS) const
CRTP base class which implements the entire standard iterator facade in terms of a minimal subset of ...
WrappedPairNodeDataIterator(ItType Begin, const DataRef DR)
std::ptrdiff_t difference_type
CRTP base class for adapting an iterator to a different type.
ReferenceProxy operator[](DifferenceTypeT n)
DerivedT & operator+=(difference_type n)
friend DerivedT operator+(DifferenceTypeT n, const DerivedT &i)
difference_type operator-(const DerivedT &RHS) const
DerivedT operator+(DifferenceTypeT n) const
iterator_adaptor_base(WrappedIteratorT u)
iterator_range< T > make_range(T x, T y)
Convenience function for iterating over sub-ranges.
ReferenceProxy operator[](DifferenceTypeT n) const
PointerT operator->() const
An iterator type that allows iterating over the pointees via some other iterator. ...
A range adaptor for a pair of iterators.
pointer_iterator(WrappedIteratorT u)
NodeRef & operator*() const
const WrappedIteratorT & wrapped() const
iterator_range< pointee_iterator< WrappedIteratorT > > make_pointee_range(RangeT &&Range)
const T & operator*() const
bool operator>(const DerivedT &RHS) const
iterator_range< pointer_iterator< WrappedIteratorT > > make_pointer_range(RangeT &&Range)