10 #ifndef LLVM_ADT_ITERATOR_H 11 #define LLVM_ADT_ITERATOR_H 17 #include <type_traits> 65 template <
typename DerivedT,
typename IteratorCategoryT,
typename T,
66 typename DifferenceTypeT = std::ptrdiff_t,
typename PointerT = T *,
67 typename ReferenceT = T &>
69 :
public std::iterator<IteratorCategoryT, T, DifferenceTypeT, PointerT,
74 IteratorCategoryT>::value,
76 IteratorCategoryT>::value,
92 operator ReferenceT()
const {
return *I; }
97 static_assert(std::is_base_of<iterator_facade_base, DerivedT>::value,
98 "Must pass the derived type to this template!");
101 "The '+' operator is only defined for random access iterators.");
102 DerivedT tmp = *
static_cast<const DerivedT *
>(
this);
106 friend DerivedT
operator+(DifferenceTypeT n,
const DerivedT &i) {
109 "The '+' operator is only defined for random access iterators.");
115 "The '-' operator is only defined for random access iterators.");
116 DerivedT tmp = *
static_cast<const DerivedT *
>(
this);
122 static_assert(std::is_base_of<iterator_facade_base, DerivedT>::value,
123 "Must pass the derived type to this template!");
124 return static_cast<DerivedT *
>(
this)->
operator+=(1);
127 DerivedT tmp = *
static_cast<DerivedT *
>(
this);
128 ++*
static_cast<DerivedT *
>(
this);
134 "The decrement operator is only defined for bidirectional iterators.");
135 return static_cast<DerivedT *
>(
this)->
operator-=(1);
140 "The decrement operator is only defined for bidirectional iterators.");
141 DerivedT tmp = *
static_cast<DerivedT *
>(
this);
142 --*
static_cast<DerivedT *
>(
this);
147 return !
static_cast<const DerivedT *
>(
this)->
operator==(RHS);
153 "Relational operators are only defined for random access iterators.");
154 return !
static_cast<const DerivedT *
>(
this)->
operator<(RHS) &&
155 !
static_cast<const DerivedT *
>(
this)->
operator==(RHS);
160 "Relational operators are only defined for random access iterators.");
161 return !
static_cast<const DerivedT *
>(
this)->
operator>(RHS);
166 "Relational operators are only defined for random access iterators.");
167 return !
static_cast<const DerivedT *
>(
this)->
operator<(RHS);
170 PointerT
operator->() {
return &
static_cast<DerivedT *
>(
this)->
operator*(); }
172 return &
static_cast<const DerivedT *
>(
this)->
operator*();
176 "Subscripting is only defined for random access iterators.");
177 return ReferenceProxy(static_cast<DerivedT *>(
this)->
operator+(n));
181 "Subscripting is only defined for random access iterators.");
182 return ReferenceProxy(static_cast<const DerivedT *>(
this)->
operator+(n));
192 typename DerivedT,
typename WrappedIteratorT,
193 typename IteratorCategoryT =
194 typename std::iterator_traits<WrappedIteratorT>::iterator_category,
195 typename T =
typename std::iterator_traits<WrappedIteratorT>::value_type,
196 typename DifferenceTypeT =
197 typename std::iterator_traits<WrappedIteratorT>::difference_type,
198 typename PointerT =
typename std::conditional<
199 std::is_same<
T,
typename std::iterator_traits<
200 WrappedIteratorT>::value_type>::value,
201 typename std::iterator_traits<WrappedIteratorT>::pointer, T *>
::type,
202 typename ReferenceT =
typename std::conditional<
203 std::is_same<
T,
typename std::iterator_traits<
204 WrappedIteratorT>::value_type>::value,
205 typename std::iterator_traits<WrappedIteratorT>::reference, T &>::type>
208 DifferenceTypeT, PointerT, ReferenceT> {
209 using BaseT =
typename iterator_adaptor_base::iterator_facade_base;
217 static_assert(std::is_base_of<iterator_adaptor_base, DerivedT>::value,
218 "Must pass the derived type to this template!");
221 const WrappedIteratorT &
wrapped()
const {
return I; }
228 BaseT::IsRandomAccess,
229 "The '+=' operator is only defined for random access iterators.");
231 return *
static_cast<DerivedT *
>(
this);
235 BaseT::IsRandomAccess,
236 "The '-=' operator is only defined for random access iterators.");
238 return *
static_cast<DerivedT *
>(
this);
240 using BaseT::operator-;
243 BaseT::IsRandomAccess,
244 "The '-' operator is only defined for random access iterators.");
250 using BaseT::operator++;
253 return *
static_cast<DerivedT *
>(
this);
255 using BaseT::operator--;
258 BaseT::IsBidirectional,
259 "The decrement operator is only defined for bidirectional iterators.");
261 return *
static_cast<DerivedT *
>(
this);
264 bool operator==(
const DerivedT &RHS)
const {
return I == RHS.I; }
267 BaseT::IsRandomAccess,
268 "Relational operators are only defined for random access iterators.");
284 template <
typename WrappedIteratorT,
285 typename T =
typename std::remove_reference<
286 decltype(**std::declval<WrappedIteratorT>())>::type>
289 pointee_iterator<WrappedIteratorT, T>, WrappedIteratorT,
290 typename std::iterator_traits<WrappedIteratorT>::iterator_category,
293 template <
typename U>
300 template <
typename RangeT,
typename WrappedIteratorT =
306 PointeeIteratorT(
std::end(std::forward<RangeT>(Range))));
309 template <
typename WrappedIteratorT,
310 typename T = decltype(&*std::declval<WrappedIteratorT>())>
313 pointer_iterator<WrappedIteratorT, T>, WrappedIteratorT,
314 typename std::iterator_traits<WrappedIteratorT>::iterator_category,
328 template <
typename RangeT,
typename WrappedIteratorT =
334 PointerIteratorT(
std::end(std::forward<RangeT>(Range))));
339 template <
typename ItType,
typename NodeRef,
typename DataRef>
342 WrappedPairNodeDataIterator<ItType, NodeRef, DataRef>, ItType,
343 typename std::iterator_traits<ItType>::iterator_category, NodeRef,
344 std::ptrdiff_t, NodeRef *, NodeRef &> {
347 typename std::iterator_traits<ItType>::iterator_category, NodeRef,
348 std::ptrdiff_t, NodeRef *, NodeRef &>;
355 :
BaseT(Begin), DR(DR) {
360 NR.second = *this->
I;
367 #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)