Where is the performance gain of the erase-remove idiom coming from
问题 I need to erase all elements from a vector which fulfill a certain criteria. My first approach would be to loop through the vector and call vector::erase on all elements which fulfill the criteria. As far as I understand, vector::erase has a bad performance for this use case, because it removes the item from the underlying array, and moves the rest of the vector forward by one element (or more if you erase a range of elements). When you remove multiple elements, the rear elements will be