¿Cómo puedo negar un functor en C ++ (STL)?
Tengo alguna función para encontrar un valor:
struct FindPredicate
{
FindPredicate(const SomeType& t) : _t(t) {
}
bool operator()(SomeType& t) {
return t == _t;
}
private:
const SomeType& _t;
};
bool ContainsValue(std::vector<SomeType>& v, SomeType& valueToFind) {
return find_if(v.begin(), v.end(), FindPredicate(valueToFind)) != v.end();
}
Ahora me gustaría escribir una función que verifique si todos los miembros de un vector satisfacen ese predicado:
bool AllSatisfy(std::vector<SomeType>& v) {
/* ... */
}
Una solución es usar elstd::count_if
algoritmo.
¿Alguien sabe una solución que implica negar el predicado?