#include #include #include #include #include "Tracer.h" #include "TracerWithHistory.h" using std::cout; using std::endl; using std::for_each; using std::vector; // Template version of Iterator Question from Lecture 14 // The "typename" in the parameter list is needed so that // the compiler knows that vector::iterator is a type // and not a field, since it doesn't know yet what T is. template void OrderPair(typename vector::iterator it1) { auto it2 = it1 + 1; if (*it2 < *it1) { auto tmp = *it2; *it2 = *it1; *it1 = tmp; } } void PrintOut(const Tracer &p) { cout << " printout: " << p << endl; } int main(int argc, char **argv) { Tracer a, b, c; vector vec; vec.push_back(c); vec.push_back(a); vec.push_back(b); cout << "\norder first 2 elements:" << endl; OrderPair(vec.begin()); cout << "done ordering!" << endl; cout << "\nprinting:" << endl; for_each(vec.begin(), vec.end(), &PrintOut); cout << "done printing!" << endl; cout << endl; return EXIT_SUCCESS; }