#ifndef DMCGRATH_CLASS_TEMPLATE_EXAMPLE_HPP #define DMCGRATH_CLASS_TEMPLATE_EXAMPLE_HPP namespace dmcgrath{ template class pair{ public: pair() : first_value(T1()), second_value(T2()) {} pair(const T1 &a, const T2 &b) : first_value(a), second_value(b){} //allow for implicit conversion //this will break...horribly...if the types are not implicitly convertible template pair(pair &p) : first_value(p.first()), second_value(p.second()){} inline const T1 first(){ return first_value; } const T2 second(){ return second_value; } //if they are both equal bool operator==(const pair &RHS){ return RHS.first_value == this->first_value && RHS.second_value == this->second_value; } bool operator!=(const pair &RHS){ return !(*this == RHS); } //first takes priority in comparison: bool operator<(const pair &RHS){ return this->first_value < RHS.first_value || (!(this->first_value < RHS.first_value) && this->second_value < RHS.second_value); } bool operator<=(const pair &RHS){ return (*this == RHS || *this < RHS); } //first takes priority in comparison: bool operator>(const pair &RHS){ return this->first_value > RHS.first_value || (!(this->first_value > RHS.first_value) && this->second_value > RHS.second_value); } private: T1 first_value; T2 second_value; }; } #endif