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* )
Definido en el encabezado <functional>
template <>
class negate < void > ;
(desde C++14)

std:: negate <> es una especialización de std::negate con tipo de parámetro y retorno deducido.

Contenidos

Tipos de miembros

Tipo Definición
is_transparent unspecified

Funciones miembro

operator()
devuelve su argumento negado
(función miembro pública)

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

template < class T >

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

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

Devuelve el resultado de negar arg .

Parámetros

arg - valor a negar

Valor de retorno

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

Ejemplo

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

Salida:

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