二元谓词

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

class Print
{
public:
   void operator()(int i)
   {
      cout << i << endl;
   }
};

class Compare
{
public:
   bool operator()(int a, int b)
   {
      return a > b;
   }
};

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

   sort(v.begin(), v.end(), Compare());
   for_each(v.begin(), v.end(), Print());

   return 0;
}
$ ./a.out 
5
3
1
posted @ 2022-07-31 10:45  thomas_blog  阅读(21)  评论(0编辑  收藏  举报