1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
|
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
struct foo {
int low, high;
foo(int l,int h):low(l),high(h){}
bool between(int v) {
return v >= low && v <= high;
}
bool operator()(int v) {
return between(v);
}
};
int main ( ) {
vector<int> a { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
foo target(4,6);
for ( auto v = a.begin() ; v != a.end() ; ++v ) {
auto x = find_if(v,a.end(),target);
if ( x != a.end() ) {
*x = 0;
v = x;
}
}
for ( auto &v : a ) {
cout << v << endl;
}
}
| |