函数
函数 | 作用 |
---|
any_of | 区间[开始, 结束)中是否至少有一个元素都满足判断式p,只要有一个元素满足条件就返回true,否则返回true |
none_of | 区间[开始, 结束)中是否所有的元素都不满足判断式p,所有的元素都不满足条件返回true,否则返回false |
all_of | 区间[开始, 结束)中是否所有的元素都满足判断式p,所有的元素都满足条件返回true,否则返回false |
示例
std::vector<int> vec_score{10 , 2, 33, 43, 52};
bool is_greater_than_100 = std::all_of(vec_score.begin(), vec_score.end(), [](int &item) {return 100 < item; });
bool is_exist_greater_than_100 = std::any_of(vec_score.begin(), vec_score.end(), [](int &item) {return 100 < item; });
bool is_less_than_100 = std::none_of(vec_score.begin(), vec_score.end(), [](int &item) {return 100 < item; });if (!is_greater_than_100)std::cout << "不全大于100\n\n";
elsestd::cout << "全大于100\n\n";if (is_exist_greater_than_100)std::cout << "存在大于100的分数\n";
elsestd::cout << "不存在大于100的分数\n\n";if (is_less_than_100)std::cout << "所有分数都不大于100\n";
elsestd::cout << "存在大于100的分数\n\n";# result
# "不全大于100"
# "不存在大于100的分数"
# "所有分数都不大于100"