9#ifndef LLVM_ADT_ITERATOR_H
10#define LLVM_ADT_ITERATOR_H
77template <
typename DerivedT,
typename IteratorCategoryT,
typename T,
78 typename DifferenceTypeT = std::ptrdiff_t,
typename PointerT =
T *,
79 typename ReferenceT =
T &>
93 IteratorCategoryT>::value,
95 IteratorCategoryT>::value,
104 class ReferenceProxy {
105 friend iterator_facade_base;
109 ReferenceProxy(DerivedT I) :
I(std::move(I)) {}
112 operator ReferenceT()
const {
return *I; }
120 friend iterator_facade_base;
124 template <
typename RefT>
125 PointerProxy(RefT &&R) : R(std::forward<RefT>(R)) {}
133 static_assert(std::is_base_of<iterator_facade_base, DerivedT>::value,
134 "Must pass the derived type to this template!");
137 "The '+' operator is only defined for random access iterators.");
138 DerivedT tmp = *
static_cast<const DerivedT *
>(
this);
142 friend DerivedT
operator+(DifferenceTypeT n,
const DerivedT &i) {
145 "The '+' operator is only defined for random access iterators.");
151 "The '-' operator is only defined for random access iterators.");
152 DerivedT tmp = *
static_cast<const DerivedT *
>(
this);
158 static_assert(std::is_base_of<iterator_facade_base, DerivedT>::value,
159 "Must pass the derived type to this template!");
160 return static_cast<DerivedT *
>(
this)->
operator+=(1);
163 DerivedT tmp = *
static_cast<DerivedT *
>(
this);
164 ++*
static_cast<DerivedT *
>(
this);
170 "The decrement operator is only defined for bidirectional iterators.");
171 return static_cast<DerivedT *
>(
this)->
operator-=(1);
176 "The decrement operator is only defined for bidirectional iterators.");
177 DerivedT tmp = *
static_cast<DerivedT *
>(
this);
178 --*
static_cast<DerivedT *
>(
this);
182#ifndef __cpp_impl_three_way_comparison
184 return !(
static_cast<const DerivedT &
>(*this) ==
RHS);
191 "Relational operators are only defined for random access iterators.");
192 return !(
static_cast<const DerivedT &
>(*this) <
RHS) &&
193 !(
static_cast<const DerivedT &
>(*
this) ==
RHS);
198 "Relational operators are only defined for random access iterators.");
199 return !(
static_cast<const DerivedT &
>(*this) >
RHS);
204 "Relational operators are only defined for random access iterators.");
205 return !(
static_cast<const DerivedT &
>(*this) <
RHS);
209 return static_cast<const DerivedT *
>(
this)->
operator*();
213 "Subscripting is only defined for random access iterators.");
214 return static_cast<const DerivedT *
>(
this)->
operator+(n);
225 typename IteratorCategoryT =
226 typename std::iterator_traits<WrappedIteratorT>::iterator_category,
227 typename T =
typename std::iterator_traits<WrappedIteratorT>::value_type,
228 typename DifferenceTypeT =
229 typename std::iterator_traits<WrappedIteratorT>::difference_type,
230 typename PointerT = std::conditional_t<
231 std::is_same<
T,
typename std::iterator_traits<
233 typename std::iterator_traits<WrappedIteratorT>::pointer,
T *>,
234 typename ReferenceT = std::conditional_t<
235 std::is_same<
T,
typename std::iterator_traits<
237 typename std::iterator_traits<WrappedIteratorT>::reference,
T &>>
240 DifferenceTypeT, PointerT, ReferenceT> {
241 using BaseT =
typename iterator_adaptor_base::iterator_facade_base;
249 static_assert(std::is_base_of<iterator_adaptor_base, DerivedT>::value,
250 "Must pass the derived type to this template!");
260 BaseT::IsRandomAccess,
261 "The '+=' operator is only defined for random access iterators.");
263 return *
static_cast<DerivedT *
>(
this);
267 BaseT::IsRandomAccess,
268 "The '-=' operator is only defined for random access iterators.");
270 return *
static_cast<DerivedT *
>(
this);
272 using BaseT::operator-;
273 template <
bool Enabled = BaseT::IsRandomAccess,
274 typename = std::enable_if_t<Enabled>>
277 BaseT::IsRandomAccess,
278 "The '-' operator is only defined for random access iterators.");
284 using BaseT::operator++;
287 return *
static_cast<DerivedT *
>(
this);
289 using BaseT::operator--;
292 BaseT::IsBidirectional,
293 "The decrement operator is only defined for bidirectional iterators.");
295 return *
static_cast<DerivedT *
>(
this);
305 BaseT::IsRandomAccess,
306 "Relational operators are only defined for random access iterators.");
323 typename T = std::remove_reference_t<
decltype(
324 **std::declval<WrappedIteratorT>())>>
331 template <
typename U>
339 decltype(std::begin(std::declval<RangeT>()))>
343 return make_range(PointeeIteratorT(std::begin(std::forward<RangeT>(
Range))),
344 PointeeIteratorT(std::end(std::forward<RangeT>(
Range))));
348 typename T =
decltype(&*std::declval<WrappedIteratorT>())>
366 decltype(std::begin(std::declval<RangeT>()))>
370 return make_range(PointerIteratorT(std::begin(std::forward<RangeT>(
Range))),
371 PointerIteratorT(std::end(std::forward<RangeT>(
Range))));
375 typename T1 = std::remove_reference_t<
decltype(
376 **std::declval<WrappedIteratorT>())>,
377 typename T2 = std::add_pointer_t<T1>>
ConstantRange Range(APInt(BitWidth, Low), APInt(BitWidth, High))
iterator_adaptor_base(WrappedIteratorT u)
const WrappedIteratorT & wrapped() const
DerivedT & operator+=(difference_type n)
difference_type operator-(const DerivedT &RHS) const
iterator_adaptor_base()=default
friend bool operator<(const iterator_adaptor_base &LHS, const iterator_adaptor_base &RHS)
DerivedT & operator-=(difference_type n)
friend bool operator==(const iterator_adaptor_base &LHS, const iterator_adaptor_base &RHS)
ReferenceT operator*() const
typename std::iterator_traits< IteratorBase >::difference_type difference_type
PointerT operator->() const
CRTP base class which implements the entire standard iterator facade in terms of a minimal subset of ...
PointerProxy operator->() const
IteratorCategoryT iterator_category
bool operator<=(const DerivedT &RHS) const
bool operator>=(const DerivedT &RHS) const
DerivedT operator-(DifferenceTypeT n) const
friend DerivedT operator+(DifferenceTypeT n, const DerivedT &i)
DifferenceTypeT difference_type
bool operator!=(const DerivedT &RHS) const
bool operator>(const DerivedT &RHS) const
DerivedT operator+(DifferenceTypeT n) const
ReferenceProxy operator[](DifferenceTypeT n) const
pointer_iterator(WrappedIteratorT u)
pointer_iterator()=default
This provides a very simple, boring adaptor for a begin and end iterator into a range type.
This is an optimization pass for GlobalISel generic memory operations.
pointer_iterator< pointee_iterator< WrappedIteratorT, T1 >, T2 > raw_pointer_iterator
iterator_range< T > make_range(T x, T y)
Convenience function for iterating over sub-ranges.
iterator_range< pointee_iterator< WrappedIteratorT > > make_pointee_range(RangeT &&Range)
iterator_range(Container &&) -> iterator_range< llvm::detail::IterOfRange< Container > >
OutputIt move(R &&Range, OutputIt Out)
Provide wrappers to std::move which take ranges instead of having to pass begin/end explicitly.
iterator_range< pointer_iterator< WrappedIteratorT > > make_pointer_range(RangeT &&Range)
@ Enabled
Convert any .debug_str_offsets tables to DWARF64 if needed.
Implement std::hash so that hash_code can be used in STL containers.
An iterator type that allows iterating over the pointees via some other iterator.
pointee_iterator()=default