Go to the documentation of this file.
4 #ifndef LEXY_DETAIL_ITERATOR_HPP_INCLUDED
5 #define LEXY_DETAIL_ITERATOR_HPP_INCLUDED
16 template <
typename Iterator>
18 template <
typename Iterator>
21 template <
typename Iterator,
typename Sentinel>
24 if constexpr (std::is_same_v<Iterator, Sentinel> && is_random_access_iterator<Iterator>)
26 return static_cast<std::size_t
>(
end -
begin);
30 std::size_t result = 0;
31 for (
auto cur =
begin; cur !=
end; ++cur)
37 template <
typename Iterator>
38 constexpr Iterator
next(Iterator iter)
42 template <
typename Iterator>
43 constexpr Iterator
next(Iterator iter, std::size_t
n)
45 if constexpr (is_random_access_iterator<Iterator>)
51 for (
auto i = 0u; i !=
n; ++i)
57 template <
typename Iterator,
typename Sentinel>
60 if constexpr (is_random_access_iterator<Iterator> && std::is_same_v<Iterator, Sentinel>)
62 auto remaining = std::size_t(
end - iter);
70 for (
auto i = 0u; i !=
n; ++i)
81 template <
typename Iterator,
typename Sentinel>
82 constexpr
bool precedes([[maybe_unused]] Iterator first, [[maybe_unused]] Sentinel after)
84 if constexpr (is_random_access_iterator<Iterator> && std::is_same_v<Iterator, Sentinel>)
85 return first <= after;
92 template <
typename Iterator>
95 if constexpr (is_random_access_iterator<Iterator>)
106 while (cur != end_a && cur != end_b)
114 template <
typename Iterator>
117 if constexpr (is_random_access_iterator<Iterator>)
132 else if (cur == end_b)
145 template <
typename T>
156 template <
typename Derived,
typename T,
typename Reference = T&,
typename Po
inter = const T*>
167 return static_cast<const Derived&
>(*this).deref();
171 if constexpr (std::is_void_v<Pointer>)
179 auto& derived =
static_cast<Derived&
>(*this);
185 auto& derived =
static_cast<Derived&
>(*this);
191 friend constexpr
bool operator==(
const Derived& lhs,
const Derived& rhs)
193 return lhs.equal(rhs);
195 friend constexpr
bool operator!=(
const Derived& lhs,
const Derived& rhs)
197 return !lhs.equal(rhs);
201 template <
typename Derived,
typename T,
typename Reference = T&,
typename Po
inter = const T*>
208 auto& derived =
static_cast<Derived&
>(*this);
214 auto& derived =
static_cast<Derived&
>(*this);
221 template <
typename Derived,
typename Iterator>
224 friend constexpr
bool operator==(
const Iterator& lhs, Derived) noexcept
228 friend constexpr
bool operator!=(
const Iterator& lhs, Derived) noexcept
230 return !(lhs == Derived{});
232 friend constexpr
bool operator==(Derived,
const Iterator& rhs) noexcept
234 return rhs == Derived{};
236 friend constexpr
bool operator!=(Derived,
const Iterator& rhs) noexcept
238 return !(rhs == Derived{});
243 #endif // LEXY_DETAIL_ITERATOR_HPP_INCLUDED
constexpr Derived & operator++() noexcept
constexpr friend bool operator!=(const Iterator &lhs, Derived) noexcept
std::remove_cv_t< node_t > value_type
constexpr bool precedes([[maybe_unused]] Iterator first, [[maybe_unused]] Sentinel after)
constexpr pointer operator->() const noexcept
std::conditional_t< std::is_void_v< T >, Fallback, T > type_or
constexpr Iterator next(Iterator iter)
#define LEXY_PRECONDITION(Expr)
constexpr auto end(const C &c) -> decltype(c.end())
constexpr Iterator max_range_end(Iterator begin, Iterator end_a, Iterator end_b)
decltype(LEXY_DECLVAL(Iterator) - LEXY_DECLVAL(Iterator)) _detect_random_access
constexpr Iterator next_clamped(Iterator iter, std::size_t n, Sentinel end)
lexy::_detail::type_or< void, _proxy_pointer< value_type > > pointer
constexpr friend bool operator!=(Derived, const Iterator &rhs) noexcept
constexpr friend bool operator!=(const Derived &lhs, const Derived &rhs)
std::ptrdiff_t difference_type
constexpr Derived & operator--() noexcept
constexpr Derived operator--(int) noexcept
constexpr std::size_t range_size(Iterator begin, Sentinel end)
constexpr auto n() noexcept
constexpr reference operator*() const noexcept
constexpr auto begin(const C &c) -> decltype(c.begin())
constexpr T * operator->() noexcept
constexpr void decrement() noexcept
constexpr friend bool operator==(Derived, const Iterator &rhs) noexcept
constexpr Iterator min_range_end(Iterator begin, Iterator end_a, Iterator end_b)
#define LEXY_DECLVAL(...)
std::forward_iterator_tag iterator_category
constexpr friend bool operator==(const Iterator &lhs, Derived) noexcept
constexpr Derived operator++(int) noexcept
constexpr friend bool operator==(const Derived &lhs, const Derived &rhs)
constexpr auto is_random_access_iterator