4#ifndef QITERATORFACADE_P_H
5#define QITERATORFACADE_P_H
18#include <QtCore/qtconfigmacros.h>
19#include <QtCore/qxptype_traits.h>
30#if defined(__cpp_concepts)
33concept has_increment = requires(T & t)
39concept has_decrement = requires(T & t)
45concept has_equals = requires(
const T &t1,
const T &t2)
62constexpr bool has_increment = qxp::is_detected<increment_expr, T>::value;
65constexpr bool has_decrement = qxp::is_detected<decrement_expr, T>::value;
68constexpr bool has_equals = qxp::is_detected<equals_expr, T>::value;
88template <
typename Derived,
typename ValueType,
typename IteratorCategory =
std::input_iterator_tag,
89 typename Reference = ValueType &,
typename DifferenceType =
std::ptrdiff_t>
100 constexpr decltype(
auto)
operator*()
const {
return derived().dereference(); }
110 Derived result = derived();
123 Derived result = derived();
128 template <
typename N>
129#if defined(__cpp_concepts)
137 derived().advance_by(n);
141 template <
typename N>
142#if defined(__cpp_concepts)
150 derived().advance_by(-n);
154 template <
typename N>
155#if defined(__cpp_concepts)
161 friend constexpr Derived
operator+(Derived it, N n)
167 template <
typename N>
168#if defined(__cpp_concepts)
174 friend constexpr Derived
operator+(N n, Derived it)
180 template <
typename N>
181#if defined(__cpp_concepts)
187 friend constexpr Derived
operator-(Derived it, N n)
193 template <
typename N>
194#if defined(__cpp_concepts)
200 friend constexpr Derived
operator-(N n, Derived it)
206 template <
typename N>
207#if defined(__cpp_concepts)
215 Derived tmp = derived();
217 return tmp.dereference();
220 friend constexpr auto operator-(
const Derived &lhs,
const Derived &rhs)
221#if defined(__cpp_concepts)
228 return rhs.distance_to(lhs);
231 friend constexpr bool operator<(
const Derived &lhs,
const Derived &rhs)
232#if defined(__cpp_concepts)
239 return lhs.distance_to(rhs) > 0;
242 friend constexpr bool operator<=(
const Derived &lhs,
const Derived &rhs)
243#if defined(__cpp_concepts)
250 return lhs.distance_to(rhs) >= 0;
253 friend constexpr bool operator>(
const Derived &lhs,
const Derived &rhs)
254#if defined(__cpp_concepts)
261 return lhs.distance_to(rhs) < 0;
264 friend constexpr bool operator>=(
const Derived &lhs,
const Derived &rhs)
265#if defined(__cpp_concepts)
272 return lhs.distance_to(rhs) <= 0;
275 friend constexpr bool operator==(
const Derived &lhs,
const Derived &rhs)
277 return lhs.equalsImpl(rhs);
280 friend constexpr bool operator!=(
const Derived &lhs,
const Derived &rhs)
282 return !lhs.equalsImpl(rhs);
286 constexpr Derived &derived() {
return static_cast<Derived &>(*
this); }
287 constexpr const Derived &derived()
const {
return static_cast<
const Derived &>(*
this); }
289 constexpr void stepForward() { stepForwardDispatch<impl::has_increment<Derived>>(); }
291 template <
bool HasIncrement>
292 constexpr void stepForwardDispatch()
294 if constexpr (HasIncrement)
295 derived().increment();
297 derived().advance_by(1);
300 constexpr void stepBackward() { stepBackwardDispatch<impl::has_decrement<Derived>>(); }
302 template <
bool HasDecrement>
303 constexpr void stepBackwardDispatch()
305 if constexpr (HasDecrement)
306 derived().decrement();
308 derived().advance_by(-1);
311 constexpr bool equalsImpl(
const Derived &other)
const
313 return equalsDispatch<impl::has_equals<Derived>>(other);
316 template <
bool HasEquals>
317 constexpr bool equalsDispatch(
const Derived &other)
const
319 if constexpr (HasEquals)
320 return derived().equals(other);
322 return derived().distance_to(other) == 0;