#include "pair_traits.h" #include #include #include using std::string; using std::cout; using std::endl; using std::complex; // for printing template void print(const pair& p, const string& label) { cout << label << ": " << p.left() << " " << p.right() << endl; } // for testing the traits class struct Employee { string name; Employee(const string& s) : name(s) { } Employee operator+(const Employee& other) { return Employee(name + other.name); } }; template<> struct my_operator_traits { typedef use_plus addition; }; // main testing routine int main() { pair A("alpha", 0.1), B("beta", 0.2); print(A, "A"); // print(B, "B"); // pair C; C = A + B; print(C, "C"); // pair, string> D1(complex(1, 2), "first"), D2(complex(3, 4), "second"); print(D1, "D1"); // print(D2, "D2"); // D1 += D2; print(D1, "D1"); // const pair E(A + B); print(E, "E"); // pair F; F.left() = "hello"; F.right() = 0.4; print(F, "F"); // // test traits class - note that adding two Employee objects will use operator+ not operator+= pair G(Employee("G"), 1000), H(Employee("H"), 2000); pair I = G + H; cout << "Employee I: " << I.left().name << endl; // return 0; }