Which one is better when select the last entry of an ordered map in c++

Viewed 69
  1. auto& myKey = myMap.rbegin()->first;
  2. auto& myKey = std::prev(myMap.end())->first;

myMap is a constant ordered map. Both of the approaches are with constant complexity. rbegin()uses reverse iterator, while std::prevworks on bidirectional iterator. Any efficiency difference between them?

1 Answers
Related