#include #include #include #include "Tracer.h" using namespace std; // 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 << "order first 2 elements:" << endl; OrderPair(vec.begin()); cout << "done ordering!" << endl; for_each(vec.begin(), vec.end(), &PrintOut); return 0; }