rbegin
rbegin is a reverse iterator access function in the C++ Standard Library. It provides a means to access the last element of a container and iterate in reverse order. The concept is the opposite of begin and is complemented by rend, which marks the end of the reverse sequence. When used, rbegin returns an iterator that moves from the last element toward the first; for empty containers, rbegin equals rend.
Types and overloads: For non-const objects, rbegin returns a reverse_iterator that wraps the container’s normal iterator.
Usage: rbegin is commonly used in explicit reverse loops. Example:
for (auto it = v.rbegin(); it != v.rend(); ++it) {
}
You can also use the non-member forms:
for (auto it = std::rbegin(v); it != std::rend(v); ++it) { ... }
rbegin and rend also apply to arrays and other standard sequence types, enabling uniform reverse traversal.
Relation to other iterators: rbegin yields a reverse_iterator that adapts a normal iterator, reversing the direction