C++11 algorithms with multiple predicates

倖福魔咒の 提交于 2019-12-02 06:09:47

问题


Functions such as std::find_if from the algorithm header are really useful, but 1 serious limit for me is the fact that I can only use 1 predicate for each call to count_if.

For example given a container like an std::vector I would like to apply, at the same time, with the same iteration of find_if, multiple predicates; there is something in the standard library that makes this possible while keeping this functional approach ?


回答1:


Just combine them with a lambda:

std::find_if(begin(vec), end(vec),
    [](elem_t val) {
        return f1(val) || f2(val);
    });


来源:https://stackoverflow.com/questions/20754848/c11-algorithms-with-multiple-predicates

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!