vendredi 18 août 2017

Does std::vector::erase() really invalidate the iterator at the point of erase?

I was playing around to understand iterator invalidation rule. However, when I run following code in c++14 compiler, output really confuses me..

std::vector<int> test = {1,2,3}; auto it = test.begin() + 1; test.erase(it); std::cout << *it << std::endl;

output = 3 shouldn't it invalidate at this point? Why it seems to jump to the next pos? Many thanks in advance

Aucun commentaire:

Enregistrer un commentaire