3.1 template<class T> T negate<T>//取反仿函数
3.2 template<class T> T plus<T>//加法仿函数
3.3 template<class T> bool greater<T>//大于
3.4 头文件 #include < functional >
void test01() {
negate<int>n;
cout << n(10) << endl;
plus<int>p;
cout << p(1, 1) << endl;
}
void test02() {
vector<int>v;
for (int i = 0; i < 10; i++) {
v.push_back(rand() % 100);
}
for_each(v.begin(), v.end(), [](int val) {cout << val << " "; });
cout << endl;
sort(v.begin(), v.end(), greater<int>());
for_each(v.begin(), v.end(), [](int val) {cout << val << " "; });
cout << endl;
}
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/7064859a974e7f9d467e938baad0b3fa.png)