一元谓词

#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

class Find
{
public:
   bool operator()(int i)
   {
      return i < 5;
   }
};

int main()
{
   vector<int> v;
   v.push_back(1);
   v.push_back(5);
   v.push_back(3);

   vector<int>::iterator it = find_if(v.begin(), v.end(), Find());
   if(it != v.end())
   {
      cout << "找到了" << endl;
   }
   else
   {
      cout << "未找到" << endl;
   }

   return 0;
}
$ ./a.out 
找到了
posted @ 2022-07-31 10:28  thomas_blog  阅读(27)  评论(0编辑  收藏  举报