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 の特殊化です。

目次

翻訳の説明: - 「Contents」を「目次」に翻訳 - HTMLタグ、属性、 内のC++コード(std::negate<void>::)は翻訳せず保持 - C++専門用語(Member types、Member functions、Parameters、Return value、Example)は翻訳せず保持 - 数値や記号はそのまま保持 - 元の書式と構造を完全に維持

メンバー型

定義
is_transparent unspecified

メンバー関数

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)