I came across this answer to the question of removing elements by value in C++:
C++ Erase vector element by value rather than by position?
Basically:
vec.erase(std::remove(vec.begin(), vec.end(), valueToRemove), vec.end());
The answer makes sense, but isn’t this bad style? The logic is consists of a double negative… is there a cleaner way to do this?
Deleting an element from a collection consists of two steps:
With the C++ standard library, these are two separate functions,
removeanderase, respectively.One could certainly imagine an
erase_iftype of function which would be easier to use, but evidently the current code is considered good enough. Of course you can write your ownremove_if.