plus
描述 (Description)
它是一个加法函数对象类和二进制函数对象类,其调用返回添加其两个参数的结果(由operator +返回)。
声明 (Declaration)
以下是std :: plus的声明。
template <class T> struct plus;
C++11
template <class T> struct plus;
参数 (Parameters)
T - 它是函数调用的参数和返回类型的一种类型。
返回值 (Return Value)
没有
异常 (Exceptions)
noexcep - 它不会抛出任何异常。
例子 (Example)
在下面的例子中解释了std :: plus。
#include <iostream>
#include <functional>
#include <algorithm>
int main () {
int first[]={15,12,30,45,15};
int second[]={10,20,30,40,50};
int results[5];
std::transform (first, first+5, second, results, std::plus<int>());
for (int i=0; i<5; i++)
std::cout << results[i] << ' ';
std::cout << '\n';
return 0;
}
让我们编译并运行上面的程序,这将产生以下结果 -
25 32 60 85 65