C++ Functional 库 - negate
描述
它是一个负函数对象类和一元函数对象类,其调用返回对其参数求反的结果(由一元运算符 - 返回)。
声明
以下是 std::negate 的声明。
template <class T> struct negate;
C++11
template <class T> struct negate;
参数
T − 它是函数调用的参数类型和返回类型。
返回值
none
异常
noexcep − 它不会抛出任何异常。
示例
在下面的例子中解释了 std::negate。
#include <iostream>
#include <functional>
#include <algorithm>
int main () {
int numbers[]={100,-200,300,-40,500,-300,200};
std::transform (numbers, numbers+5, numbers, std::negate<int>());
for (int i=0; i<4; i++)
std::cout << numbers[i] << ' ';
std::cout << '\n';
return 0;
}
让我们编译并运行上面的程序,这将产生以下结果 −
-100 200 -300 40

