Header lexy/input/range_input.hpp

Input lexy::range_input

namespace lexy
    template <encoding Encoding,
              typename Iterator, typename Sentinel = Iterator>
    class range_input
        requires std::forward_iterator<Iterator>
              && std::sentinel_for<Sentinel, Iterator>
        using encoding  = Encoding;
        using char_type = typename encoding::char_type;

        using iterator = Iterator;
        using sentinel = Sentinel;

        //=== constructors ===//
        constexpr range_input() noexcept;
        constexpr range_input(iterator begin, sentinel end) noexcept;

        //=== access ===//
        constexpr iterator begin() const noexcept;
        constexpr iterator end()   const noexcept;

        constexpr reader auto reader() const& noexcept;

    template <typename Iterator, typename Sentinel>
    range_input(Iterator begin, Sentinel end)
      -> range_input<deduce-encoding, Iterator, Sentinel>;

The class range_input uses the forward range [begin, end) as input.

It is a lightweight view and does not own any data. If no template arguments are specified, CTAD is used to deduce the encoding from the value type of the iterator.

Example 1. Use a std::list as input
int main()
    std::list<char16_t> list{u'H', u'i'};

    // Create the input, deducing the encoding.
    auto input = lexy::range_input(list.begin(), list.end());

    // Use the input.
    if (!lexy::match<production>(input))
        return 1;
If the iterators are pointers, use lexy::string_input  instead.
If you’re parsing a subset of an input, use lexy::lexeme_input instead.

See also