#include #include #include #include #include "date.h" #include "sorter2.h" using namespace std; inline bool f(int a, int b) {return a > b;} class greater_int { public: bool operator()(int a, int b) const {return a > b;} }; class greater_date { public: bool operator()(const date& a, const date& b) const {return a > b;} }; template void print(ITERATOR first, ITERATOR last, char c) { for (; first != last; ++first) { cout << *first << c; } cout << "\n"; } int main() { int a1[] = {10, 30, 20, 50, 40}; const size_t n1 = sizeof a1 / sizeof a1[0]; sorter(a1, a1 + n1, f); print(a1, a1 + n1, ' '); greater_int gi; sorter(a1, a1 + n1, gi); print(a1, a1 + n1, ' '); sorter(a1, a1 + n1, greater_int()); //construct an anonymous object print(a1, a1 + n1, ' '); const date a2[] = { date(date::october, 29, 1929), date(date::july, 20, 1969), date(date::july, 4, 1776), date(date::september, 11, 2001), date(date::december, 7, 1941) }; const size_t n2 = sizeof a2 / sizeof a2[0]; vector v(a2, a2 + n2); sorter(v.begin(), v.end(), greater_date()); print(v.begin(), v.end(), '\n'); return EXIT_SUCCESS; }