二元函数对象:重载运算符()的函数有两个参数
二元谓词:函数有两个输入参数,并且返回值为bool类型
具体的可以看如下代码:
#include<iostream>
using namespace std;
#include "string"
#include <vector>
#include <list>
#include "set"
#include <algorithm>
#include "functional"
//二元函数对象
template<typename T>
class SumAdd
{
public:
T operator()(T& t1, T& t2)
{
return t1 + t2;
}
};
void main04()
{
vector<int> v1, v2;
vector<int> v3;
v1.push_back(1);
v1.push_back(3);
v1.push_back(5);
v2.push_back(2);
v2.push_back(4);
v2.push_back(6);
v3.resize(10);
transform(v1.begin(),v1.end(),v2.begin(),v3.begin(), SumAdd<int>());
for (vector<int>::iterator it = v3.begin(); it != v3.end(); it++)
{
cout << *it << " "; //输出3 7 11 0 0 0 0 0 0 0
}
cout << endl;
}
//二元谓词
template<typename T>
bool MyCompare