#include #include #include #include #include "date.h" using namespace std; int main() { const int a[] = {10, 50, 30, 40, 20}; //need not be sorted for find const size_t n = sizeof a / sizeof a[0]; const int *const p = find(a, a + n, 30); if (p == a + n) { cout << "Didn't find 30.\n"; } else { cout << "Found 30 at position " << p - a << ".\n"; } const date d[] = { date(date::october, 29, 1929), date(date::july, 4, 1776), date(date::july, 20, 1969), date(date::september, 11, 2001), date(date::december, 7, 1941) }; const size_t n1 = sizeof d / sizeof d[0]; vector v(d, d + n1); const date moon(date::july, 20, 1969); const vector::const_iterator it1 = find(v.begin(), v.end(), moon); if (it1 == v.end()) { cout << "Didn't find " << moon << ".\n"; } else { cout << "Found " << moon << " at position " << it1 - v.begin() << ".\n"; } const vector::const_iterator it2 = find(v.begin(), v.end(), date(date::july, 4, 1776)); if (it2 == v.end()) { cout << "Didn't find it.\n"; } else { cout << "Found it at position " << it2 - v.begin() << ".\n"; } return EXIT_SUCCESS; }