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