std::negate<void>
来自cppreference.com
< cpp | utility | functional
在标头 <functional> 定义 | ||
template<> class negate<void>; | (C++14 起) | |
std::negate<void> 是会推导形参类型和返回类型的 std::negate 特化。
目录 |
[编辑]成员类型
类型 | 定义 |
is_transparent | 未指定 |
[编辑]成员函数
operator() | 返回实参的相反数 (公开成员函数) |
std::negate<void>::operator()
template<class T > constexprauto operator()( T&& arg )const | ||
返回对 arg 取负的结果。
参数
arg | - | 要取反的值 |
返回值
-std::forward<T>(arg)。
[编辑]示例
运行此代码
#include <complex>#include <functional>#include <iostream> int main(){auto complex_negate =std::negate<void>{};// 可以省略 “void”constexprstd::complex z(4, 2);std::cout<< z <<'\n';std::cout<<-z <<'\n';std::cout<< complex_negate(z)<<'\n';}
输出:
(4,2) (-4,-2) (-4,-2)