c++ 判断数组元素是否有负数(any_of)

#include <iostream>     // std::cout
#include <algorithm>    // std::any_of
#include <array>        // std::array
using namespace std;
int main () {
    array<int,7> foo = {0,1,-1,3,-3,5,-5};
    
    if ( any_of(foo.begin(), foo.end(), [](int i){return i<0;}) )
        cout << "There are negative elements in the range.
";
    
    return 0;
}

原文地址:https://www.cnblogs.com/sea-stream/p/9814972.html