#include #include #include #include //for greater, less, logical_and, bind2nd #include //for compose2 using namespace std; inline bool greater_than_30(int i) {return i > 30;} 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 *p = find_if(a, a + n, greater_than_30); if (p == a + n) { cout << "Found no int greater than 30.\n"; } else { cout << "Found " << *p << " at position " << p - a << ".\n"; } p = find_if(a, a + n, bind2nd(greater(), 30)); if (p == a + n) { cout << "Found no int greater than 30.\n"; } else { cout << "Found " << *p << " at position " << p - a << ".\n"; } p = find_if(a, a + n, __gnu_cxx::compose2( logical_and(), bind2nd(greater(), 35), bind2nd( less(), 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"; } return EXIT_SUCCESS; }