I was looking for the most efficient and expressive way to remove the last element from a std::map. I tried:
#include <map>
int main()
{
std::map<int, int> m;
m.insert(std::make_pair(1,1));
m.erase(m.crbegin());
return 0;
}
The code does not compile, since std::map::erase can take only std::map::const_iterator.
Moreover, prior to C++11 it could take std::map::iterators as well, but for some reason, this functionality was removed too.
What is the motivation behind these restrictions?
Aucun commentaire:
Enregistrer un commentaire