Skip to content

Instantly share code, notes, and snippets.

@meshell
Created February 22, 2016 21:12
Show Gist options
  • Save meshell/22a789f9dc8134a8127d to your computer and use it in GitHub Desktop.
Save meshell/22a789f9dc8134a8127d to your computer and use it in GitHub Desktop.
Erase Remove idiom
#include <vector>
#include <algorithm>
int main() {
std::vector<int> v = {1, 2, 3, 4, 2, 5, 2, 6};
v.erase(std::remove(std::begin(v),
std::end(v),
2),
std::end(v));
// using a custom predicate
v.erase(std::remove_if(std::begin(v),
std::end(v),
[](int i) {
return i%2 == 0;
}),
std::end(v));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment