Skip to content

Instantly share code, notes, and snippets.

@mstybird
Created October 19, 2016 12:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mstybird/38a8de05329fbaee3064927991c515f7 to your computer and use it in GitHub Desktop.
Save mstybird/38a8de05329fbaee3064927991c515f7 to your computer and use it in GitHub Desktop.
C++ Vector std::remove_if
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
template<typename T>
void OutVector(vector<T>&aData) {
for (auto&x : aData) {
cout << x << ",";
}
cout << endl;
}
int main() {
vector<int> data = {
1,2,3,2,3,4,5,2,3
};
OutVector(data);
//値に2を持つ要素を削除
auto removeIt = remove_if(data.begin(), data.end(), [&](int value) {
return value == 2;
}
);
//これで初めて要素が削除される
data.erase(removeIt, data.end());
OutVector(data);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment