std:: binary_negate
|
Definido en el encabezado
<functional>
|
||
|
template
<
class
Predicate
>
struct
binary_negate
|
(hasta C++11) | |
|
template
<
class
Predicate
>
struct binary_negate ; |
(desde C++11)
(obsoleto en C++17) (eliminado en C++20) |
|
std::binary_negate
es una función contenedora de objeto que devuelve el complemento del predicado binario que contiene.
El tipo de predicado binario debe definir dos tipos de miembros,
first_argument_type
y
second_argument_type
, que sean convertibles a los tipos de parámetros del predicado. Los objetos función obtenidos de
std::owner_less
,
std::ref
,
std::cref
,
std::plus
,
std::minus
,
std::multiplies
,
std::divides
,
std::modulus
,
std::equal_to
,
std::not_equal_to
,
std::greater
,
std::less
,
std::greater_equal
,
std::less_equal
,
std::logical_not
,
std::logical_or
,
std::bit_and
,
std::bit_or
,
std::bit_xor
,
std::mem_fn
,
std::map::value_comp
,
std::multimap::value_comp
,
std::function
, o de una llamada a
std::not2
tienen estos tipos definidos, al igual que los objetos función derivados del obsoleto
std::binary_function
.
std::binary_negate
los objetos se construyen fácilmente con la función auxiliar
std::not2
.
Contenidos |
Tipos de miembros
| Tipo | Definición |
first_argument_type
|
Predicate :: first_argument_type |
second_argument_type
|
Predicate :: second_argument_type |
result_type
|
bool |
Funciones miembro
|
(constructor)
|
construye un nuevo objeto binary_negate con el predicado proporcionado
(función miembro pública) |
|
operator()
|
devuelve el complemento lógico del resultado de una llamada al predicado almacenado
(función miembro pública) |
std::binary_negate:: binary_negate
|
explicit
binary_negate
(
Predicate
const
&
pred
)
;
|
(hasta C++14) | |
|
constexpr
explicit
binary_negate
(
Predicate
const
&
pred
)
;
|
(desde C++14) | |
Construye un objeto de función
std::binary_negate
con el predicado almacenado
pred
.
Parámetros
| pred | - | objeto de función predicado |
std::binary_negate:: operator()
|
bool
operator
(
)
(
first_argument_type
const
&
x,
second_argument_type const & y ) const ; |
(hasta C++14) | |
|
constexpr
bool
operator
(
)
(
first_argument_type
const
&
x,
second_argument_type const & y ) const ; |
(desde C++14) | |
Devuelve el complemento lógico del resultado de llamar a pred ( x, y ) .
Parámetros
| x | - | primer argumento para pasar al predicado |
| y | - | segundo argumento para pasar al predicado |
Valor de retorno
El complemento lógico del resultado de llamar a pred ( x, y ) .
Ejemplo
#include <algorithm> #include <cstddef> #include <functional> #include <iostream> #include <vector> struct same : std::binary_function<int, int, bool> { bool operator()(int a, int b) const { return a == b; } }; int main() { std::vector<int> v1; for (int i = 0; i < 7; ++i) v1.push_back(i); std::vector<int> v2(v1.size()); std::reverse_copy(v1.begin(), v1.end(), v2.begin()); std::vector<bool> v3(v1.size()); std::binary_negate<same> not_same((same())); // C++11 solution: // std::function<bool (int, int)> not_same = // [](int x, int y) -> bool { return !same()(x, y); }; std::transform(v1.begin(), v1.end(), v2.begin(), v3.begin(), not_same); std::cout.setf(std::ios_base::boolalpha); for (std::size_t i = 0; i != v1.size(); ++i) std::cout << v1[i] << " != " << v2[i] << " : " << v3[i] << '\n'; }
Salida:
0 != 6 : true 1 != 5 : true 2 != 4 : true 3 != 3 : false 4 != 2 : true 5 != 1 : true 6 != 0 : true
Véase también
|
(deprecated in C++11)
(removed in C++17)
|
clase base de función binaria compatible con adaptadores
(class template) |
|
(C++11)
|
envoltorio copiable de cualquier objeto invocable copiable
(class template) |
|
(C++23)
|
envoltorio no copiable de cualquier objeto invocable que admita calificadores en una signatura de llamada dada
(class template) |
|
(deprecated in C++17)
(removed in C++20)
|
construye objetos personalizados
std::binary_negate
(function template) |
|
(deprecated in C++11)
(removed in C++17)
|
crea un envoltorio de objeto función compatible con adaptadores desde un puntero a función
(function template) |
|
(deprecated in C++17)
(removed in C++20)
|
objeto función envoltorio que devuelve el complemento del predicado unario que contiene
(class template) |