二元谓词
#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