I wrote this simple test program. But i can't understand what happens here. Because there is a strange thing in the output:
std::list<std::pair<double,double>> l; l.push_back({0.3,0.9}); l.push_back({-0.3,0.5}); l.push_back({0.3,0.7}); l.push_back({1.2,1.83}); for(auto it=l.begin(); it!=l.end(); ++it){ double lx= it->first + 0.01; double ly= it->second + 0.01; it->first = lx; it->second = ly; if(lx < 0.0 || lx > 1.0 || ly < 0.0 || ly > 1.0){ it = l.erase(it); } If i print the list, i get:
0.32, 0.92 0.31, 0.71 Why does the iterator goes back to the first element (twice +0.1) ?
==0in the if is superfluous, in fact the whole if is useless because theit != end()will take care of that. And I'm not sure why you said the first element is there twice? It looks like youre removing elements at position 1 and 3 and therefore printing elements 0 and 2.l.erase(std::remove_if(...), l.end()).removeing is illegal. Annoying, but true.