Home

constreverseiterator

A const_reverse_iterator is a read-only reverse iterator used to traverse a container in reverse order. It is the const version of a reverse iterator, meaning that dereferencing yields a const reference to the element and the element cannot be modified through the iterator. This type is provided by the C++ standard library for standard containers such as vector, deque, list, set, and map, typically as a nested typedef named const_reverse_iterator.

In most containers, const_reverse_iterator is defined as reverse_iterator<const_iterator>, where const_iterator is the container’s iterator type that

The base() member function returns the corresponding underlying iterator, typically a const_iterator, pointing to the element

Since const_reverse_iterator enforces constness, it is commonly obtained via crbegin and crend (introduced in C++17) to

Overall, const_reverse_iterator provides a standard, read-only means to traverse containers in reverse, complementing reverse_iterator and const_iterator

yields
a
const
reference
to
the
element.
The
reverse
iterator
adapts
a
bidirectional
iterator
and
traverses
the
container
from
end
to
beginning.
Dereferencing
it
yields
a
const
reference
to
the
element,
and
operator->
yields
a
pointer
to
const
T.
Incrementing
a
const_reverse_iterator
moves
toward
the
beginning
of
the
container
(i.e.,
it
advances
the
reverse
traversal),
while
decrementing
moves
toward
the
end,
opposite
to
the
direction
of
a
forward
iterator.
that
would
be
visited
next
by
a
forward
iteration.
This
allows
one
to
translate
between
reverse
and
forward
views
when
needed.
perform
read-only
reverse
traversal.
This
is
useful
when
iterating
const
containers
or
when
read-only
access
is
required
while
walking
elements
from
end
to
start.
in
the
C++
iterator
toolbox.