HikoGUI
A low latency retained GUI
Loading...
Searching...
No Matches
hi::v1::lookahead_iterator< LookaheadCount, It, ItEnd > Class Template Reference

#include <hikogui/parser/lookahead_iterator.hpp>

Data Structures

class  proxy

Public Types

using value_type = std::iterator_traits<It>::value_type
using reference = value_type const &
using pointer = value_type const *
using difference_type = std::ptrdiff_t
using iterator_category = std::forward_iterator_tag

Public Member Functions

constexpr lookahead_iterator (lookahead_iterator const &) noexcept=delete
constexpr lookahead_iterator (lookahead_iterator &&) noexcept=default
constexpr lookahead_iterator & operator= (lookahead_iterator const &) noexcept=delete
constexpr lookahead_iterator & operator= (lookahead_iterator &&) noexcept=default
constexpr lookahead_iterator (It first, ItEnd last) noexcept
constexpr size_t size () const noexcept
 The number of entries can be looked ahead.
constexpr bool empty () const noexcept
 Check if the iterator is at end.
constexpr operator bool () const noexcept
constexpr bool operator== (std::default_sentinel_t) const noexcept
constexpr reference operator[] (size_t i) const noexcept
 Get a reference to an item at or beyond the iterator.
constexpr reference at (size_t i) const
 Get a reference to an item at or beyond the iterator.
constexpr std::optional< value_type > next (size_t i=1) const noexcept
 Get a reference to an item at or beyond the iterator.
constexpr reference operator* () const noexcept
 Get a reference to the value at the iterator.
constexpr pointer operator-> () const noexcept
 Get a pointer to the value at the iterator.
constexpr lookahead_iterator & operator++ () noexcept
 Increment the iterator.
constexpr lookahead_iterator & operator+= (size_t n) noexcept
constexpr proxy operator++ (int) noexcept

Static Public Attributes

static constexpr size_t max_size = LookaheadCount

Detailed Description

template<size_t LookaheadCount, typename It, std::sentinel_for< It > ItEnd = std::default_sentinel_t>
class hi::v1::lookahead_iterator< LookaheadCount, It, ItEnd >

Lookahead iterator.

This iterator adapter takes a forward input iterator and adapts it so that you can look ahead beyond the current position of the iterator. This is useful when writing a parser.

Member Function Documentation

◆ at()

template<size_t LookaheadCount, typename It, std::sentinel_for< It > ItEnd = std::default_sentinel_t>
reference hi::v1::lookahead_iterator< LookaheadCount, It, ItEnd >::at ( size_t i) const
inlinenodiscardconstexpr

Get a reference to an item at or beyond the iterator.

Parameters
iIndex to lookahead, 0 means the current iterator, larger than zero is lookahead.
Exceptions
std::out_of_rangewhen index beyond the lookahead buffer.
Returns
A reference to the item.

◆ empty()

template<size_t LookaheadCount, typename It, std::sentinel_for< It > ItEnd = std::default_sentinel_t>
bool hi::v1::lookahead_iterator< LookaheadCount, It, ItEnd >::empty ( ) const
inlinenodiscardconstexprnoexcept

Check if the iterator is at end.

Return values
trueIterator at end.

◆ next()

template<size_t LookaheadCount, typename It, std::sentinel_for< It > ItEnd = std::default_sentinel_t>
std::optional< value_type > hi::v1::lookahead_iterator< LookaheadCount, It, ItEnd >::next ( size_t i = 1) const
inlinenodiscardconstexprnoexcept

Get a reference to an item at or beyond the iterator.

Parameters
iIndex to lookahead, 0 means the current iterator, larger than zero is lookahead.
Return values
std::nulloptWhen the index points beyond the lookahead buffer.
Returns
A reference to the item.

◆ operator*()

template<size_t LookaheadCount, typename It, std::sentinel_for< It > ItEnd = std::default_sentinel_t>
reference hi::v1::lookahead_iterator< LookaheadCount, It, ItEnd >::operator* ( ) const
inlineconstexprnoexcept

Get a reference to the value at the iterator.

◆ operator++()

template<size_t LookaheadCount, typename It, std::sentinel_for< It > ItEnd = std::default_sentinel_t>
lookahead_iterator & hi::v1::lookahead_iterator< LookaheadCount, It, ItEnd >::operator++ ( )
inlineconstexprnoexcept

Increment the iterator.

◆ operator->()

template<size_t LookaheadCount, typename It, std::sentinel_for< It > ItEnd = std::default_sentinel_t>
pointer hi::v1::lookahead_iterator< LookaheadCount, It, ItEnd >::operator-> ( ) const
inlineconstexprnoexcept

Get a pointer to the value at the iterator.

◆ operator[]()

template<size_t LookaheadCount, typename It, std::sentinel_for< It > ItEnd = std::default_sentinel_t>
reference hi::v1::lookahead_iterator< LookaheadCount, It, ItEnd >::operator[] ( size_t i) const
inlinenodiscardconstexprnoexcept

Get a reference to an item at or beyond the iterator.

Parameters
iIndex to lookahead, 0 means the current iterator, larger than zero is lookahead.
Returns
A reference to the item.

◆ size()

template<size_t LookaheadCount, typename It, std::sentinel_for< It > ItEnd = std::default_sentinel_t>
size_t hi::v1::lookahead_iterator< LookaheadCount, It, ItEnd >::size ( ) const
inlinenodiscardconstexprnoexcept

The number of entries can be looked ahead.

Returns
Number of entries that can be looked ahead, including the current entry.

The documentation for this class was generated from the following file: