Espacios de nombres
Variantes

std::not1

De cppreference.com
 
 
Biblioteca de servicios
Apoyo del lenguaje
Apoyo de tipos (tipos básicos, RTTI)
Macros de prueba de característica de la biblioteca (C++20)
Servicios de programa
Funciones variádicas
Apoyo de corrutinas (C++20)
Apoyo de contratos (C++26)
Comparación de tres vías (C++20)
(C++20)
(C++20)(C++20)(C++20)  
(C++20)(C++20)(C++20)

 
Objetos función
Envoltorios de funciones
(C++11)
(C++11)
Aplicación parcial de funciones
(C++20)
(C++11)
Invocación de funciones
(C++17)(C++23)
Objeto función identidad
(C++20)
Envoltorios de referencias
(C++11)(C++11)
Envoltorios de operador transparentes
(C++14)
(C++14)
(C++14)
(C++14)
(C++14)
(C++14)
(C++14)
(C++14)
(C++14)
(C++14)
(C++14)
(C++14)
Negadores
(C++17)
Buscadores
Comparadores restringidos
Vinculadores y adaptadores antiguos
(hasta C++17)
(hasta C++17)
(hasta C++17)
(hasta C++17)
(hasta C++17)(hasta C++17)(hasta C++17)(hasta C++17)
(hasta C++20)
(hasta C++20)
(hasta C++17)(hasta C++17)
(hasta C++17)(hasta C++17)

(hasta C++17)
(hasta C++17)(hasta C++17)(hasta C++17)(hasta C++17)
(hasta C++20)
(hasta C++20)
 
Definido en el archivo de encabezado <functional>
template< class Predicate >
std::unary_negate<Predicate> not1(const Predicate& pred);
not1 es una función auxiliar para crear un objeto de función que devuelve el complemento de la función de predicado unario pasado. El objeto creado es función de std::unary_negate<Predicate> tipo .
Original:
not1 is a helper function to create a function object that returns the complement of the unary predicate function passed. The function object created is of type std::unary_negate<Predicate>.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
El tipo de predicado unario debe definir un tipo de miembro, argument_type, que se puede convertir en el tipo de parámetro del predicado. Los objetos de la función unarios obtenidos de std::ref, std::cref, std::negate, std::logical_not, std::mem_fn, std::function, std::hash, o de otra llamada a std::not1 han definido este tipo, como son objetos función derivada de la std::unary_function obsoleto .
Original:
The unary predicate type must define a member type, argument_type, that is convertible to the predicate's parameter type. The unary function objects obtained from std::ref, std::cref, std::negate, std::logical_not, std::mem_fn, std::function, std::hash, or from another call to std::not1 have this type defined, as are function objects derived from the deprecated std::unary_function.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

Parámetros

pred -
predicado unario
Original:
unary predicate
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

Valor de retorno

std::not1 devuelve un objeto de tipo std::unary_negate<Predicate>, construido con pred .
Original:
std::not1 returns an object of type std::unary_negate<Predicate>, constructed with pred.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

Excepciones

Ninguno .
Original:
None.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

Ejemplo

#include <algorithm>
#include <functional>
#include <iostream>
#include <vector>

struct LessThan7 : std::unary_function<int, bool>
{
    bool operator()(int i) const { return i < 7; }
};

int main()
{
    std::vector<int> v;
    for (int i = 0; i < 10; ++i) {
        v.push_back(i);
    }
    
    std::cout << std::count_if(v.begin(), v.end(), std::not1(LessThan7())) << "\n";
    
    //same as above, but use a lambda function
    std::function<int(int)> less_than_9 = [](int x){ return x < 9; };
    std::cout << std::count_if(v.begin(), v.end(), std::not1(less_than_9)) << "\n";
}

Salida:

3

Ver también

(en desuso en C++17)(eliminado en C++20)
Envoltorio de objeto función que devuelve el complemento del predicado unario que mantiene.
(plantilla de clase) [editar]
(C++11)
Envuelve un objeto que puede ser llamado a cualquier tipo con la signatura de llamada a función especificada.
(plantilla de clase) [editar]
(en desuso en C++17)(eliminado en C++20)
Construye un objeto std::binary_negate personalizado.
(plantilla de función) [editar]
(en desuso en C++11)(eliminado en C++17)
Crea un envoltorio de objeto función compatible con un adaptador de un puntero a función
(plantilla de función) [editar]
(en desuso en C++11)(eliminado en C++17)
Clase base de función unaria compatible con un adaptador.
(plantilla de clase) [editar]
Morty Proxy This is a proxified and sanitized view of the page, visit original site.