#ifndef _UTILITY_H_ #define _UTILITY_H_ //#include "Algorithm.h" namespace TinySTL{ //************ [swap] *************** template void swap(T& a, T& b){ T temp = a; a = b; b = temp; } //*********** [pair] **************** template struct pair{ public: typedef T1 first_type; typedef T2 second_type; public: T1 first; T2 second; public: pair(){} template pair(const pair& pr); pair(const first_type& a, const second_type& b); pair& operator= (const pair& pr); void swap(pair& pr); public: template friend bool operator== (const pair& lhs, const pair& rhs); template friend bool operator!= (const pair& lhs, const pair& rhs); template friend bool operator< (const pair& lhs, const pair& rhs); template friend bool operator<= (const pair& lhs, const pair& rhs); template friend bool operator> (const pair& lhs, const pair& rhs); template friend bool operator>= (const pair& lhs, const pair& rhs); template friend void swap(pair& x, pair& y); }; template template pair::pair(const pair& pr) :first(pr.first), second(pr.second){} template pair::pair(const first_type& a, const second_type& b) : first(a), second(b){} template pair& pair::operator =(const pair& pr){ if (this != &pr){ first = pr.first; second = pr.second; } return *this; } template void pair::swap(pair& pr){ TinySTL::swap(first, pr.first); TinySTL::swap(second, pr.second); } template bool operator== (const pair& lhs, const pair& rhs){ return lhs.first == rhs.first && lhs.second == rhs.second; } template bool operator!= (const pair& lhs, const pair& rhs){ return !(lhs == rhs); } template bool operator< (const pair& lhs, const pair& rhs){ return lhs.first bool operator<= (const pair& lhs, const pair& rhs){ return !(rhs bool operator>(const pair& lhs, const pair& rhs){ return rhs bool operator>= (const pair& lhs, const pair& rhs){ return !(lhs void swap(pair& x, pair& y){ x.swap(y); } // ******* [make_pair] ************ template pair make_pair(const U& u, const V& v){ return pair(u, v); } } #endif