#include<iostream>
using namespace std;
#include<vector>
#include<functional>
#include<algorithm>
//仿函数原型
//template<class T> bool equal_to<T>//等于
//template<class T> bool not_equal_to<T>不等于
//template<class T> bool greater<T>大于
//template<class T> bool greater_equal<T>大于于等于
//template<class T> bool less<T> 小于
//template<class T> bool less_equal<T>小于等于
void test0501()
{
vector<int> v;
v.push_back(10);
v.push_back(130);
v.push_back(140);
v.push_back(1);
v.push_back(130);
for (vector<int>::iterator it = v.begin(); it != v.end(); it++)
{
cout << (*it) << " ";
}
cout << endl;
sort(v.begin(), v.end(), greater<int>());//通过内建仿函数创建的匿名对象指定排序规则
for (vector<int>::iterator it = v.begin(); it != v.end(); it++)
{
cout << (*it) << " ";
}
cout << endl;
greater<int> g;
cout << g(1, 2) << endl;
}
int main()
{
test0501();
system("pause");
return 0;
}
网友评论