六个算数运算符
plus<type>
//加法
minus<type>
//减法
negetive<type>
//否定
multiplies<type>
//乘法
divides<type>
//除法
modules<type>
//取模
代码示例:
#include <iostream>
#include <numeric>
#include <vector>
#include <functional>
using namespace std;
int main()
{
int ia[] = { 1,2,3,4,5 };
vector<int> iv(ia, ia + 5);
//120
cout << accumulate(iv.begin(), iv.end(), 1, multiplies<int>()) << endl;
//15
cout << multiplies<int>()(3, 5) << endl;
modulus<int> modulusObj;
cout << modulusObj(3, 5) << endl; // 3
system("pause");
return 0;
}
六个关系运算类仿函数
less<type>
//小于
less_equal<type>
//小于等于
greater<type>
//大于
greater_equal<type>
//大于等于
equal_to<type>
//等于
not_equal<type>
//不等于
代码示例:
#include <iostream>
#include <algorithm>
#include<functional>
#include <vector>
using namespace std;
template <class T>
class display
{
public:
void operator()(const T &x)
{
cout << x << " ";
}
};
int main()
{
int ia[] = { 1,5,4,3,2 };
vector<int> iv(ia, ia + 5);
sort(iv.begin(), iv.end(), greater<int>());
for_each(iv.begin(), iv.end(), display<int>());
system("pause");
return 0;
}
三个逻辑运算符
logic_and<type>
//逻辑于
logic_and<type>
//逻辑或
logic_not<type>
//逻辑否