谓词的概念
- 返回bool类型的仿函数称为谓词
- 如果operator()接受一个参数,那么叫做一元谓词
- 如果operator()接受两个参数,那么叫做二元谓词
案例演示
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
class GreatFive
{
public:
bool operator()(int val)
{
return val > 5;
}
};
void test1()
{
vector<int> v;
for (int i = 0; i < 10; i++)
{
v.push_back(i);
}
vector<int> :: iterator it = find_if(v.begin(), v.end(), GreatFive());
if (it == v.end())
{
cout << "未找到" << endl;
}
else
{
cout << *it << endl;
}
}
int main()
{
test1();
system("pause");
return 0;
}