![在这里插入图片描述](https://img-blog.csdnimg.cn/20200429102509305.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FxXzQ1OTc2OTUw,size_16,color_FFFFFF,t_70)
逻辑仿函数
#include<iostream>
#include<functional>
#include<vector>
#include<algorithm>
using namespace std;
void test01()
{
vector<bool>v;
v.push_back(true);
v.push_back(false);
v.push_back(true);
v.push_back(false);
v.push_back(true);
for (vector<bool>::iterator it = v.begin(); it != v.end(); it++)
{
cout << *it << " ";
}
cout << endl;
vector<bool>v2;
v2.resize(v.size());
transform(v.begin(), v.end(), v2.begin(), logical_not<bool>());
for (vector<bool>::iterator it = v2.begin(); it != v2.end(); it++)
{
cout << *it << " ";
}
cout << endl;
}
int main()
{
test01();
system("pause");
return 0;
}
![在这里插入图片描述](https://img-blog.csdnimg.cn/20200429102631269.jpg?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FxXzQ1OTc2OTUw,size_16,color_FFFFFF,t_70)
关系仿函数
#include<iostream>
#include<functional>
#include<vector>
#include<algorithm>
using namespace std;
void test01()
{
vector<int>v;
v.push_back(10);
v.push_back(30);
v.push_back(40);
v.push_back(20);
v.push_back(50);
for (vector<int>::iterator it = v.begin(); it != v.end(); it++)
{
cout << *it << " ";
}
cout << endl;
greater<int>g;
sort(v.begin(),v.end(),g);
for (vector<int>::iterator it = v.begin(); it != v.end(); it++)
{
cout << *it << " ";
}
cout << endl;
}
int main()
{
test01();
system("pause");
return 0;
}
![在这里插入图片描述](https://img-blog.csdnimg.cn/20200429102712160.jpg?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FxXzQ1OTc2OTUw,size_16,color_FFFFFF,t_70)
算术仿函数
#include<iostream>
#include<functional>
using namespace std;
void test01()
{
negate<int>n;
cout << n(50) << endl;
}
void test02()
{
plus<int>p;
cout << p(10, 20) << endl;
}
int main()
{
test02();
system("pause");
return 0;
}