std::vector<int> tmpVec;
for (size_t i = 0; i < 10; i++)
{
tmpVec.push_back(i);
}
class tmpClassCon{
public:
tmpClassCon(int con){
_con = con;
}
bool operator()(int val){
return val > _con;
}
private:
int _con;
};
std::vector<int>::iterator val =
std::find_if(tmpVec.begin(), tmpVec.end(), tmpClassCon(3));
printf("val is %d.\n", *val);
这个例子是在vector中查找大于3个第一个值,所以打印结果应该是4
val is 4.
请按任意键继续. . .
这个例子参考 C== PRIMER 5TH 的P508