-
Notifications
You must be signed in to change notification settings - Fork 16
/
any_of_all_of.cpp
40 lines (31 loc) · 1.04 KB
/
any_of_all_of.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#include <iostream>
#include <vector>
#include <algorithm> //std::any_of
//http://www.cplusplus.com/reference/algorithm/any_of/
//http://www.cplusplus.com/reference/algorithm/all_of/
int main() {
std::vector<bool> vec = {false, true, false};
if(std::any_of(vec.begin(), vec.end(), [](const bool& b){return b;})){
std::cout << "There is at least one true!" << std::endl;
}else{
std::cout << "They are all false!" << std::endl;
}
vec = {false, false, false};
if(std::any_of(vec.begin(), vec.end(), [](const bool& b){return b;})){
std::cout << "There is at least one true!" << std::endl;
}else{
std::cout << "They are all false!" << std::endl;
}
vec = {true, true, false};
if(std::all_of(vec.begin(), vec.end(), [](const bool& b){return b;})){
std::cout << "They are all true!" << std::endl;
}else{
std::cout << "There is at least one false!" << std::endl;
}
return 0;
}
/*
There is at least one true!
They are all false!
There is at least one false!
*/