相关疑难解决方法(0)

如何在C++(STL)中否定一个仿函数?

我有一些功能来找到一个值:

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算法.

有没有人知道一个涉及否定谓词的解决方案?

c++ algorithm stl

14
推荐指数
2
解决办法
4200
查看次数

标签 统计

algorithm ×1

c++ ×1

stl ×1