我有一些功能来找到一个值:
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();
}
Run Code Online (Sandbox Code Playgroud)
现在我想编写一个函数来检查向量的所有成员是否满足该谓词:
bool AllSatisfy(std::vector<SomeType>& v) {
/* ... */
}
Run Code Online (Sandbox Code Playgroud)
一种解决方案是使用该std::count_if算法.
有没有人知道一个涉及否定谓词的解决方案?