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; }
返回值:所有的元素都满足pred(*first)返回true,或者范围为空。结果返回true。否则返回false
#include <algorithm>
#include <iostream>
int main() {
std::array<int, 8> foo = {1,3,5,7,9,11,13,15};
if(std::all_of(foo.begin(), foo.end(), [](int i){return i%2;}))
std::cout << "all are odd numbers...
";
}