算数仿函数原型:
template<class T> T plus<T>
//加法仿函数template<class T> T minus<T>
//减法仿函数template<class T> T multiplies<T>
//乘法仿函数template<class T> T divides<T>
//除法仿函数template<class T> T modulus<T>
//取模仿函数template<class T> T negate<T>
//取反仿函数
这些仿函数所产生的对象,用法和一般函数完全相同
使用内建函数对象,需要引入头文件 #include<functional>
#include<iostream>
#include<algorithm>
#include<functional>//包含内建函数对象的头文件
using namespace std;
//取反,一元运算,即需要一个参数
void test01()
{
negate<int> n;
cout << n(100) << endl;//输出 -100
}
//加 减 乘 除 取余 ,二元运算,即需要两个参数
void test02()
{
//加法
plus<int> p;
cout << p(100,20) << endl;//输出120
//减法
minus<int> min;
cout << min(100, 20) << endl;//输出80
//乘法
multiplies<int> mul;
cout << mul(100, 20) << endl;//输出2000
//除法
divides<int> div;
cout << div(100, 20) << endl;//输出5
//取模运算(取余)
modulus<int> mod;
cout << mod(100, 23) << endl;//余数为8
}
int main()
{
//test01();
test02();
return 0;
}