In C++11, std::set::crbegin() returns a read-only reverse iterator (const_reverse_iterator) that starts at the last value, the biggest one.
The letters c and r stand for const and reverse. It is the right choice when you walk a set backwards and must not change it. Include <set> to use it.
This is a member of std::set<T>, a sorted container of unique values. A set never keeps a duplicate and always holds its values in sorted order, so it can find, insert, and erase a value in logarithmic time. A set has no operator[] and no at(), because the value is its own key. Every element is const, so you cannot change a value through an iterator.
Syntax
Call crbegin with empty brackets. Pair it with crend().
C++
auto it = s.crbegin(); // biggest value, read-only
for (auto p = s.crbegin(); p != s.crend(); ++p) {
// read only, biggest first
}
Call
What it does
s.crbegin()
Returns a const_reverse_iterator to the last value, even when the set is not const.
A function that takes const std::set& gets read-only iterators anyway. crbegin() is most useful when you hold a non-const set but want to promise that this loop only reads.