Namespaces
Variants

std:: negate<void>

From cppreference.net
Utilities library
Function objects
Function invocation
(C++17) (C++23)
Identity function object
(C++20)
Old binders and adaptors
( until C++17* )
( until C++17* )
( until C++17* )
( until C++17* )
( until C++17* ) ( until C++17* ) ( until C++17* ) ( until C++17* )
( until C++20* )
( until C++20* )
( until C++17* ) ( until C++17* )
( until C++17* ) ( until C++17* )

( until C++17* )
( until C++17* ) ( until C++17* ) ( until C++17* ) ( until C++17* )
( until C++20* )
( until 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” 可省略
    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)