Last key in a std::map
Yes. Map is a sorted container, the reverse iterator must return the elements in reverse (i.e. decreasing) order of their keys.
[Edit: as Charles Bailey points out in his answer, your code gives the greatest key if it exists - i.e. if the map is non-empty]
Yes, but remember to check that map.rbegin() != map.rend()
.
You can use following method :-
if(!map.empty())
(--map.end())->first;
One more way -
std::prev(map.end())->first;