#include #include #include #include using namespace std; /* Compile on i5.nyu.edu with /opt/gcc450/bin/g++ -std=c++0x find_if1.C */ int main() { const int a[] = {10, 30, 20, 40, 50}; //need not be sorted for find_if const size_t n = sizeof a / sizeof a[0]; const int *const p = find_if(a, a + n, [] (int x) {return x > 35 && x < 45;}); if (p == a + n) { cout << "Found no int in the range 35 to 45 exclusive.\n"; } else { cout << "Found " << *p << " at position " << p - a << ".\n"; } copy(a, a + n, ostream_iterator(cout, "\n")); return EXIT_SUCCESS; }