It is easiest to understand this if you seperate the statements:
auto iter(remove_if(myVector.begin(), myVector.end(), StringLengthTest));
myVector.erase(iter);
These 2 lines do the same as your single line. And it should be clear now what the "bug" is. remove_if, works first. It iterates over the whole vector and moves all "selected" entries "to the end" (better said: it moves the non selected entries to the front). After it has run it returns an iterator to the "last" position of the left over entries, something like:
this
test
vector
test <- iterator points here
vector
Then you run erase with a single iterator. That means you erase a single element pointed at - so you erase the "test" element. - What is left over is what you are seeing.
To fix it simply erase from the vector returned by remove_if to the end().:
myVector.erase(remove_if(myVector.begin(), myVector.end(), StringLengthTest), myVector.end()); //erase anything in vector with length <= 3
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…