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* )
Definiert im Header <functional>
template <>
class negate < void > ;
(seit C++14)

std:: negate <> ist eine Spezialisierung von std::negate mit abgeleitetem Parameter- und Rückgabetyp.

Inhaltsverzeichnis

Mitgliedertypen

Typ Definition
is_transparent unspecified

Memberfunktionen

operator()
gibt sein negiertes Argument zurück
(öffentliche Elementfunktion)

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

template < class T >

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

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

Gibt das Ergebnis der Negation von arg zurück.

Parameter

arg - zu negierender Wert

Rückgabewert

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

Beispiel

#include <complex>
#include <functional>
#include <iostream>
int main()
{
    auto complex_negate = std::negate<void>{}; // "void" kann weggelassen werden
    constexpr std::complex z(4, 2);
    std::cout << z << '\n';
    std::cout << -z << '\n';
    std::cout << complex_negate(z) << '\n';
}

Ausgabe:

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