命名空间
变体
操作

std::negate<void>

来自 cppreference.cn
< cpp‎ | utility‎ | functional
 
 
 
函数对象
函数调用
(C++17)(C++23)
恒等函数对象
(C++20)
透明运算符包装器
(C++14)
(C++14)
negate<>
(C++14)
(C++14)  
(C++14)
(C++14)
(C++14)
(C++14)
(C++14)
(C++14)
(C++14)
(C++14)
(C++14)

旧式绑定器和适配器
(直到 C++17*)
(直到 C++17*)
(直到 C++17*)
(直到 C++17*)  
(直到 C++17*)
(直到 C++17*)(直到 C++17*)(直到 C++17*)(直到 C++17*)
(直到 C++20*)
(直到 C++20*)
(直到 C++17*)(直到 C++17*)
(直到 C++17*)(直到 C++17*)

(直到 C++17*)
(直到 C++17*)(直到 C++17*)(直到 C++17*)(直到 C++17*)
(直到 C++20*)
(直到 C++20*)
 
定义于头文件 <functional>
template<>
class negate<void>;
(自 C++14 起)

std::negate<>std::negate 的特化,参数和返回类型会被推导。

目录

[编辑] 成员类型

类型 定义
is_transparent 未指定

[编辑] 成员函数

operator()
返回其取反的参数
(公共成员函数)

std::negate<void>::operator()

template< class T >

constexpr auto operator()( T&& arg ) const

    -> decltype(-std::forward<T>(arg));

返回 arg 取反的结果。

参数

arg - 要取反的值

返回值

-std::forward<T>(arg).

[编辑] 示例

#include <complex>
#include <functional>
#include <iostream>
 
int main()
{
    auto complex_negate = std::negate<void>{}; // “void” can be omitted
    constexpr std::complex z(4, 2);
    std::cout << z << '\n';
    std::cout << -z << '\n';
    std::cout << complex_negate(z) << '\n';
}

输出

(4,2)
(-4,-2)
(-4,-2)