9#ifndef WPIUTIL_WPI_ITERATOR_H
10#define WPIUTIL_WPI_ITERATOR_H
77template <
typename DerivedT,
typename IteratorCategoryT,
typename T,
78 typename DifferenceTypeT = std::ptrdiff_t,
typename PointerT = T *,
79 typename ReferenceT = T &>
91 IteratorCategoryT>::value,
93 IteratorCategoryT>::value,
109 operator ReferenceT()
const {
return *I; }
121 template <
typename RefT>
130 static_assert(std::is_base_of<iterator_facade_base, DerivedT>::value,
131 "Must pass the derived type to this template!");
134 "The '+' operator is only defined for random access iterators.");
135 DerivedT tmp = *
static_cast<const DerivedT *
>(
this);
139 friend DerivedT
operator+(DifferenceTypeT n,
const DerivedT &i) {
142 "The '+' operator is only defined for random access iterators.");
148 "The '-' operator is only defined for random access iterators.");
149 DerivedT tmp = *
static_cast<const DerivedT *
>(
this);
155 static_assert(std::is_base_of<iterator_facade_base, DerivedT>::value,
156 "Must pass the derived type to this template!");
157 return static_cast<DerivedT *
>(
this)->
operator+=(1);
160 DerivedT tmp = *
static_cast<DerivedT *
>(
this);
161 ++*
static_cast<DerivedT *
>(
this);
167 "The decrement operator is only defined for bidirectional iterators.");
168 return static_cast<DerivedT *
>(
this)->
operator-=(1);
173 "The decrement operator is only defined for bidirectional iterators.");
174 DerivedT tmp = *
static_cast<DerivedT *
>(
this);
175 --*
static_cast<DerivedT *
>(
this);
179#ifndef __cpp_impl_three_way_comparison
181 return !(
static_cast<const DerivedT &
>(*this) == RHS);
188 "Relational operators are only defined for random access iterators.");
189 return !(
static_cast<const DerivedT &
>(*this) < RHS) &&
190 !(
static_cast<const DerivedT &
>(*
this) == RHS);
195 "Relational operators are only defined for random access iterators.");
196 return !(
static_cast<const DerivedT &
>(*this) > RHS);
201 "Relational operators are only defined for random access iterators.");
202 return !(
static_cast<const DerivedT &
>(*this) < RHS);
206 return static_cast<const DerivedT *
>(
this)->
operator*();
210 "Subscripting is only defined for random access iterators.");
211 return static_cast<const DerivedT *
>(
this)->
operator+(n);
221 typename DerivedT,
typename WrappedIteratorT,
222 typename IteratorCategoryT =
223 typename std::iterator_traits<WrappedIteratorT>::iterator_category,
224 typename T =
typename std::iterator_traits<WrappedIteratorT>::value_type,
225 typename DifferenceTypeT =
226 typename std::iterator_traits<WrappedIteratorT>::difference_type,
228 std::is_same<T,
typename std::iterator_traits<
229 WrappedIteratorT>::value_type>::value,
230 typename std::iterator_traits<WrappedIteratorT>::pointer, T *>,
232 std::is_same<T,
typename std::iterator_traits<
233 WrappedIteratorT>::value_type>::value,
234 typename std::iterator_traits<WrappedIteratorT>::reference, T &>>
237 DifferenceTypeT, PointerT, ReferenceT> {
238 using BaseT =
typename iterator_adaptor_base::iterator_facade_base;
246 static_assert(std::is_base_of<iterator_adaptor_base, DerivedT>::value,
247 "Must pass the derived type to this template!");
250 const WrappedIteratorT &
wrapped()
const {
return I; }
257 BaseT::IsRandomAccess,
258 "The '+=' operator is only defined for random access iterators.");
260 return *
static_cast<DerivedT *
>(
this);
264 BaseT::IsRandomAccess,
265 "The '-=' operator is only defined for random access iterators.");
267 return *
static_cast<DerivedT *
>(
this);
269 using BaseT::operator-;
272 BaseT::IsRandomAccess,
273 "The '-' operator is only defined for random access iterators.");
279 using BaseT::operator++;
282 return *
static_cast<DerivedT *
>(
this);
284 using BaseT::operator--;
287 BaseT::IsBidirectional,
288 "The decrement operator is only defined for bidirectional iterators.");
290 return *
static_cast<DerivedT *
>(
this);
295 return LHS.
I == RHS.
I;
300 BaseT::IsRandomAccess,
301 "Relational operators are only defined for random access iterators.");
302 return LHS.
I < RHS.
I;
317template <
typename WrappedIteratorT,
319 **std::declval<WrappedIteratorT>())>>
323 typename std::iterator_traits<WrappedIteratorT>::iterator_category,
326 template <
typename U>
333template <
typename RangeT,
typename WrappedIteratorT =
334 decltype(std::begin(std::declval<RangeT>()))>
338 return make_range(PointeeIteratorT(std::begin(std::forward<RangeT>(Range))),
339 PointeeIteratorT(std::end(std::forward<RangeT>(Range))));
342template <
typename WrappedIteratorT,
343 typename T =
decltype(&*std::declval<WrappedIteratorT>())>
347 typename std::iterator_traits<WrappedIteratorT>::iterator_category,
360template <
typename RangeT,
typename WrappedIteratorT =
361 decltype(std::begin(std::declval<RangeT>()))>
365 return make_range(PointerIteratorT(std::begin(std::forward<RangeT>(Range))),
366 PointerIteratorT(std::end(std::forward<RangeT>(Range))));
369template <
typename WrappedIteratorT,
371 **std::declval<WrappedIteratorT>())>,
372 typename T2 = std::add_pointer_t<T1>>
CRTP base class for adapting an iterator to a different type.
Definition: iterator.h:237
DerivedT & operator--()
Definition: iterator.h:285
const WrappedIteratorT & wrapped() const
Definition: iterator.h:250
ReferenceT operator*() const
Definition: iterator.h:305
WrappedIteratorT I
Definition: iterator.h:241
iterator_adaptor_base()=default
iterator_adaptor_base(WrappedIteratorT u)
Definition: iterator.h:245
DerivedT & operator-=(difference_type n)
Definition: iterator.h:262
DifferenceTypeT difference_type
Definition: iterator.h:253
difference_type operator-(const DerivedT &RHS) const
Definition: iterator.h:270
friend bool operator<(const iterator_adaptor_base &LHS, const iterator_adaptor_base &RHS)
Definition: iterator.h:297
DerivedT & operator++()
Definition: iterator.h:280
DerivedT & operator+=(difference_type n)
Definition: iterator.h:255
friend bool operator==(const iterator_adaptor_base &LHS, const iterator_adaptor_base &RHS)
Definition: iterator.h:293
A proxy object for computing a pointer via indirecting a copy of a reference.
Definition: iterator.h:116
PointerT operator->() const
Definition: iterator.h:125
A proxy object for computing a reference via indirecting a copy of an iterator.
Definition: iterator.h:101
CRTP base class which implements the entire standard iterator facade in terms of a minimal subset of ...
Definition: iterator.h:80
bool operator!=(const DerivedT &RHS) const
Definition: iterator.h:180
bool operator<=(const DerivedT &RHS) const
Definition: iterator.h:192
PointerT pointer
Definition: iterator.h:85
bool operator>(const DerivedT &RHS) const
Definition: iterator.h:185
bool operator>=(const DerivedT &RHS) const
Definition: iterator.h:198
DerivedT operator+(DifferenceTypeT n) const
Definition: iterator.h:129
DerivedT operator--(int)
Definition: iterator.h:170
ReferenceProxy operator[](DifferenceTypeT n) const
Definition: iterator.h:208
friend DerivedT operator+(DifferenceTypeT n, const DerivedT &i)
Definition: iterator.h:139
DerivedT operator++(int)
Definition: iterator.h:159
DifferenceTypeT difference_type
Definition: iterator.h:84
ReferenceT reference
Definition: iterator.h:86
DerivedT operator-(DifferenceTypeT n) const
Definition: iterator.h:145
IteratorCategoryT iterator_category
Definition: iterator.h:82
PointerProxy operator->() const
Definition: iterator.h:205
T value_type
Definition: iterator.h:83
@ IsBidirectional
Definition: iterator.h:92
@ IsRandomAccess
Definition: iterator.h:90
DerivedT & operator++()
Definition: iterator.h:154
DerivedT & operator--()
Definition: iterator.h:164
Definition: iterator.h:348
T & operator*() const
Definition: iterator.h:357
pointer_iterator(WrappedIteratorT u)
Definition: iterator.h:354
pointer_iterator()=default
typename std::remove_reference< T >::type remove_reference_t
Definition: core.h:261
typename std::conditional< B, T, F >::type conditional_t
Definition: core.h:258
This provides a very simple, boring adaptor for a begin and end iterator into a range type.
Definition: ntcore_cpp.h:26
iterator_range(Container &&) -> iterator_range< detail::IterOfRange< Container > >
iterator_range< pointee_iterator< WrappedIteratorT > > make_pointee_range(RangeT &&Range)
Definition: iterator.h:336
iterator_range< pointer_iterator< WrappedIteratorT > > make_pointer_range(RangeT &&Range)
Definition: iterator.h:363
iterator_range< T > make_range(T x, T y)
Convenience function for iterating over sub-ranges.
Definition: iterator_range.h:75
An iterator type that allows iterating over the pointees via some other iterator.
Definition: iterator.h:324
T & operator*() const
Definition: iterator.h:330
pointee_iterator(U &&u)
Definition: iterator.h:327
pointee_iterator()=default