@@ -179,36 +179,24 @@ The template function returns **true** only if, for each `N` in the range `[0,La
179
179
#include <algorithm>
180
180
#include <iostream>
181
181
182
- // Returns whether element is even
183
- bool is_even(int elem)
182
+ int main()
184
183
{
184
+ using namespace std;
185
185
186
- return elem % 2 == 0 ;
187
- }
186
+ list<int> li { 50, 40, 10, 20, 20 } ;
187
+ list<int>::iterator iter;
188
188
189
- int main()
190
- {
191
- using namespace std;
192
- list <int> L;
193
- list <int>::iterator Iter;
194
- list <int>::iterator result1, result2;
195
-
196
- L.push_back(50);
197
- L.push_back(40);
198
- L.push_back(10);
199
- L.push_back(20);
200
- L.push_back(20);
201
-
202
- cout << "L = ( ";
203
- for (Iter = L.begin(); Iter != L.end(); Iter++)
204
- cout << *Iter << " ";
205
- cout << ")" << endl;
206
-
207
- // Check if all elements in L are even.
208
- if (all_of(L.begin(), L.end(), is_even))
209
- cout << "All the elements are even numbers.\n";
210
- else
211
- cout << "Not all the elements are even numbers.\n";
189
+ cout << "li = ( ";
190
+ for (iter = li.begin(); iter != li.end(); iter++)
191
+ cout << *iter << " ";
192
+ cout << ")" << endl;
193
+
194
+ // Check if all elements in li are even.
195
+ auto is_even = [](int elem){ return !(elem % 2); };
196
+ if (all_of(li.begin(), li.end(), is_even))
197
+ cout << "All the elements are even numbers.\n";
198
+ else
199
+ cout << "Not all the elements are even numbers.\n";
212
200
}
213
201
```
214
202
@@ -217,7 +205,6 @@ L = ( 50 40 10 20 20 )
217
205
All the elements are even numbers.
218
206
```
219
207
220
-
221
208
## <a name =" any_of " ></a > any_of
222
209
223
210
Returns ** true** when a condition is present at least once in the specified range of elements.
0 commit comments