Created
February 22, 2016 21:12
-
-
Save meshell/22a789f9dc8134a8127d to your computer and use it in GitHub Desktop.
Erase Remove idiom
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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