template <class InputIterator, class UnaryPredicate> bool all_of (InputIterator first, InputIterator last, UnaryPredicate pred); |
template<class InputIterator, class UnaryPredicate> bool all_of (InputIterator first, InputIterator last, UnaryPredicate pred) { while (first!=last) { if (!pred(*first)) return false; ++first; } return true; } |
// all_of example #include <iostream> // std::cout #include <algorithm> // std::all_of #include <array> // std::array int main () { std::array<int,8> foo = {3,5,7,11,13,17,19,23}; if ( std::all_of(foo.begin(), foo.end(), [](int i){return i%2;}) ) std::cout << "All the elements are odd numbers.\n"; return 0; } |
any_of | 测试范围内是否有满足条件的元素(函数模板) |
none_of | 测试是否没有元素满足条件(函数模板) |
find_if | 在范围内查找元素(函数模板) |