Home

stdcrend

std::crend is a function in the C++ standard library that returns a const_reverse_iterator to the end of a reversed range. Introduced in C++11 and defined in the<iterator> header, it is the const counterpart to std::rend and is used together with std::crbegin to perform read-only reverse iteration over a container or array.

Purpose and behavior

std::crend provides the end sentinel for reverse iteration. When paired with std::crbegin, it defines a range

Typical usage

A common pattern is:

- for (auto it = std::crbegin(v); it != std::crend(v); ++it) { use *it; }

This will access the elements of v in reverse order without mutating them. For readability, some code

Relation to other iterators

std::crend is the const version of std::rend and pairs with std::crbegin to enable read-only reverse traversal.

Notes

There are overloads of std::crend for standard containers and for array types. In modern C++ (C++20 and

that
yields
elements
in
reverse
order
without
allowing
modification
through
the
iterator.
The
value
returned
by
std::crend
corresponds
to
one
element
before
the
beginning
of
the
container
in
reverse
iteration,
so
a
loop
using
crbegin
and
crend
visits
all
elements
from
last
to
first.
favors
range-based
loops
with
explicit
reverse
iteration
where
appropriate.
It
is
distinct
from
std::rend,
which
yields
a
non-const
reverse_iterator,
allowing
modification
of
elements
through
the
reverse
iterator.
later),
ranges
introduce
additional
concepts
such
as
std::ranges::crend,
providing
similar
functionality
within
the
ranges
framework.