mardi 3 mai 2016

How to call erase with a reverse iterator using a for loop

Regarding the answer provided here: How to call erase with a reverse iterator

The following results in a segmentation fault (upon ++it) when compiled in g++ 4.8.4 with -std=c++11. Am I misunderstanding the answer?

  std::map<int,int> testmap;
  testmap[0] = 1;
  for(auto it=testmap.rbegin(); it!=testmap.rend(); ++it) {
    testmap.erase( std::next(it).base() );
  }

Aucun commentaire:

Enregistrer un commentaire