I want to delete all elements of a vector v which are contained by v2;
Is this solution good or should I use something else ?
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int main()
{
std::vector<int> v = {1,2,3,4,5,1,2};
std::vector<int> v2 = {1,2,3};
v.erase(std::remove_if(v.begin(), v.end(), [v2](int x)
{
auto it = std::find(v2.begin(), v2.end(), x);
return it != v2.end();
}), v.end());
for (auto i : v)
{
std::cout<<i<< " ";
}
return 0;
}
Output:
4 5