#include #include #include #include #include //for greater, less, logical_and, bind2nd #include //for compose2 #include "date.h" using namespace std; inline bool fox(const date& d) { static const date turn_of_the_century(date::january, 1, 1901); return d >= turn_of_the_century; //return operator>=(d, turn_of_the_century); } int main() { date d[] = { date(date::july, 4, 1776), date(date::october, 29, 1929), date(date::july, 20, 1969), date(date::december, 7, 1941), date(date::september, 11, 2001) }; const size_t n = sizeof d / sizeof d[0]; vector v(d, d + n); vector::const_iterator it = find_if(v.begin(), v.end(), fox); if (it == v.end()) { cout << "Found no date greater than or equal to January 1, 1901.\n"; } else { cout << "Found " << *it << " at position " << it - v.begin() << ".\n"; } it = find_if(v.begin(), v.end(), bind2nd(greater_equal(), date(date::january, 1, 1901))); if (it == v.end()) { cout << "Found no date greater than or equal to January 1, 1901.\n"; } else { cout << "Found " << *it << " at position " << it - v.begin() << ".\n"; } it = find_if(v.begin(), v.end(), __gnu_cxx::compose2( logical_and(), bind2nd(greater_equal(), date(date::january, 1, 1901)), bind2nd( less(), date(date::january, 1, 2001)) ) ); if (it == v.end()) { cout << "Found no twentieth century date.\n"; } else { cout << "Found " << *it << " at position " << it - v.begin() << ".\n"; } return EXIT_SUCCESS; }