Home

inputrange

Inputrange is a term used in the C++ ranges library to describe a range whose iterator models the InputIterator concept. Such ranges support single-pass iteration: you can traverse the sequence from beginning to end by repeatedly advancing the iterator, but they do not guarantee that a second, independent pass will reproduce the same sequence without reinitializing the range.

A range is considered an input range if its begin and end (or a sentinel) are compatible

Examples of input ranges include adapters over input streams, such as reading from standard input or other

Input ranges contrast with forward ranges, which guarantee multi-pass iteration: a program can restart the traversal

In modern C++ (C++20 and later), std::ranges::input_range is a concept that classifies ranges whose iterator models

and
the
iterator
type
satisfies
the
requirements
of
an
InputIterator.
In
practice,
this
means
the
range
can
be
iterated
sequentially,
but
it
may
not
support
multi-pass
iteration
or
repeated
dereferences
of
the
same
position.
The
end
of
the
range
may
be
defined
by
a
sentinel
type
rather
than
a
contrasting
iterator
type.
stream
sources,
where
data
is
consumed
in
a
single
forward
pass.
While
many
standard
library
components
can
present
input
ranges,
they
do
not
guarantee
that
the
same
value
will
remain
accessible
after
the
iterator
has
advanced.
and
produce
the
same
results
from
the
beginning.
Consequently,
algorithms
that
require
multiple
passes
or
re-access
to
previously
seen
elements
must
either
operate
on
a
forward
(or
stronger)
range
or
be
designed
to
work
with
single-pass
input
ranges.
InputIterator,
providing
a
formal,
standard
way
to
express
this
capability
in
templates
and
in
library
code.