10#include "../utility/module.hpp"
25template<
size_t LookaheadCount,
typename It, std::sentinel_for<It> ItEnd = std::default_sentinel_t>
28 static_assert(std::has_single_bit(LookaheadCount),
"LookaheadCount must be a power of two.");
30 constexpr static size_t max_size = LookaheadCount;
33 using reference = value_type
const &;
34 using pointer = value_type
const *;
44 constexpr explicit lookahead_iterator(It first, ItEnd last) noexcept : _it(first), _last(last), _size(0)
46 while (_size != max_size and first != last) {
47 add_one_to_lookahead();
55 [[nodiscard]]
constexpr size_t size() const noexcept
64 [[nodiscard]]
constexpr bool empty() const noexcept
69 constexpr explicit operator bool() const noexcept
74 [[nodiscard]]
constexpr bool operator==(std::default_sentinel_t)
const noexcept
84 [[nodiscard]]
constexpr reference
operator[](
size_t i)
const noexcept
87 return _lookahead[(_tail + i) % max_size];
96 [[nodiscard]]
constexpr reference
at(
size_t i)
const
111 [[nodiscard]]
constexpr std::optional<value_type>
next(
size_t i = 1) const noexcept
143 add_one_to_lookahead();
150 for (
auto i = 0_uz; i != n; ++i) {
169 constexpr void add_one_to_lookahead() noexcept
174 _lookahead[(_tail + _size) % max_size] = *_it;
181static_assert(std::movable<lookahead_iterator<2, std::string::iterator, std::string::iterator>>);
182static_assert(std::is_same_v<std::iterator_traits<lookahead_iterator<2, std::string::iterator, std::string::iterator>>::value_type,
char>);
183static_assert(std::input_or_output_iterator<lookahead_iterator<2, std::string::iterator, std::string::iterator>>);
184static_assert(std::weakly_incrementable<lookahead_iterator<2, std::string::iterator, std::string::iterator>>);
193template<
size_t LookaheadCount,
typename It, std::sentinel_for<It> ItEnd = std::default_sentinel_t>
206template<
size_t LookaheadCount, std::ranges::range Range>
209 return make_lookahead_iterator<LookaheadCount>(std::ranges::begin(range), std::ranges::end(range));
#define hi_axiom(expression,...)
Specify an axiom; an expression that is true.
Definition assert.hpp:253
DOXYGEN BUG.
Definition algorithm.hpp:13
geometry/margins.hpp
Definition cache.hpp:11
auto make_lookahead_iterator(It first, ItEnd last=std::default_sentinel) noexcept
Create a lookahead_iterator from a forward iterator.
Definition lookahead_iterator.hpp:194
Lookahead iterator.
Definition lookahead_iterator.hpp:26
constexpr lookahead_iterator & operator++() noexcept
Increment the iterator.
Definition lookahead_iterator.hpp:138
constexpr size_t size() const noexcept
The number of entries can be looked ahead.
Definition lookahead_iterator.hpp:55
constexpr pointer operator->() const noexcept
Get a pointer to the value at the iterator.
Definition lookahead_iterator.hpp:130
constexpr reference at(size_t i) const
Get a reference to an item at or beyond the iterator.
Definition lookahead_iterator.hpp:96
constexpr std::optional< value_type > next(size_t i=1) const noexcept
Get a reference to an item at or beyond the iterator.
Definition lookahead_iterator.hpp:111
constexpr reference operator[](size_t i) const noexcept
Get a reference to an item at or beyond the iterator.
Definition lookahead_iterator.hpp:84
constexpr reference operator*() const noexcept
Get a reference to the value at the iterator.
Definition lookahead_iterator.hpp:122
constexpr bool empty() const noexcept
Check if the iterator is at end.
Definition lookahead_iterator.hpp:64