File tree 1 file changed +14
-4
lines changed
1 file changed +14
-4
lines changed Original file line number Diff line number Diff line change 3
3
#include < algorithm> // std::any_of
4
4
5
5
// http://www.cplusplus.com/reference/algorithm/any_of/
6
+ // http://www.cplusplus.com/reference/algorithm/all_of/
6
7
7
8
int main () {
8
9
std::vector<bool > vec = {false , true , false };
9
-
10
+
10
11
if (std::any_of (vec.begin (), vec.end (), [](const bool & b){return b;})){
11
12
std::cout << " There is at least one true!" << std::endl;
12
13
}else {
13
14
std::cout << " They are all false!" << std::endl;
14
15
}
15
-
16
+
16
17
vec = {false , false , false };
17
-
18
+
18
19
if (std::any_of (vec.begin (), vec.end (), [](const bool & b){return b;})){
19
20
std::cout << " There is at least one true!" << std::endl;
20
21
}else {
21
22
std::cout << " They are all false!" << std::endl;
22
23
}
23
-
24
+
25
+ vec = {true , true , false };
26
+
27
+ if (std::all_of (vec.begin (), vec.end (), [](const bool & b){return b;})){
28
+ std::cout << " They are all true!" << std::endl;
29
+ }else {
30
+ std::cout << " There is at least one false!" << std::endl;
31
+ }
32
+
24
33
return 0 ;
25
34
}
26
35
27
36
/*
28
37
There is at least one true!
29
38
They are all false!
39
+ There is at least one false!
30
40
*/
You can’t perform that action at this time.
0 commit comments