mirror of
https://github.com/VictorEijkhout/TheArtOfHPC_vol3_cppf08programming.git
synced 2026-01-24 22:44:48 +09:00
40 lines
909 B
C++
40 lines
909 B
C++
/****************************************************************
|
|
****
|
|
**** This file belongs with the course
|
|
**** Introduction to Scientific Programming in C++/Fortran2003
|
|
**** copyright 2018-2022 Victor Eijkhout eijkhout@tacc.utexas.edu
|
|
****
|
|
**** range.cxx : range-based iteration over a class
|
|
****
|
|
****************************************************************/
|
|
|
|
#include <iostream>
|
|
using std::boolalpha;
|
|
using std::cout;
|
|
|
|
#include <vector>
|
|
using std::vector;
|
|
|
|
#include <algorithm>
|
|
using std::any_of;
|
|
|
|
int main() {
|
|
|
|
cout << "ANY.." << '\n';
|
|
//codesnippet rangeany
|
|
vector<int> integers{1,2,3,5,7,10};
|
|
auto any_even = any_of
|
|
( integers.begin(),integers.end(),
|
|
[=] (int i) -> bool {
|
|
return i%2==0; }
|
|
);
|
|
if (any_even)
|
|
cout << "there was an even" << '\n';
|
|
else
|
|
cout << "none were even" << '\n';
|
|
//codesnippet end
|
|
cout << "..any" << '\n';
|
|
|
|
return 0;
|
|
}
|