问题
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