remove
#include <algorithm>
#include <iostream>
#include <vector>
using std::vector,
std::remove,
std::cerr;
class Temp{
public:
int a, b;
Temp(int i, int j):a(i), b(j){}
};
bool operator==(const Temp& l, const Temp& r)
{
return l.a == r.a && l.b == r.b;
}
typedef vector<Temp> my_vector;
int main(){
my_vector a = {Temp(0, 0), Temp(1, 1), Temp(2, 4), Temp(3, 9), Temp(2, 4)};
auto print = [] (Temp t){
cerr << "Temp(" << t.a << ", " << t.b << ")\n";
};
for_each(a.begin(), a.end(), print);
cerr << "\n";
//this is a 2 step process of remove then erase.
my_vector::iterator i = remove(a.begin(), a.end(), Temp(2, 4));
a.erase(i, a.end());
for_each(a.begin(), a.end(), print);
return 0;
}
C++ Examples© 2024 TBD