2009-08-09
pair同士の加減乗除テンプレート
library | |
template <typename T1, typename T2> pair<T1,T2> operator+(pair<T1,T2> p1, pair<T1,T2> p2) { return make_pair(p1.first+p2.first, p1.second+p2.second); } template <typename T1, typename T2> pair<T1,T2> operator+=(pair<T1,T2>& p1, pair<T1,T2> p2) { p1.first += p2.first; p1.second += p2.second; return p1; } template <typename T1, typename T2> pair<T1,T2> operator-(pair<T1,T2> p1, pair<T1,T2> p2) { return make_pair(p1.first-p2.first, p1.second-p2.second); } template <typename T1, typename T2> pair<T1,T2> operator-=(pair<T1,T2>& p1, pair<T1,T2> p2) { p1.first -= p2.first; p1.second -= p2.second; return p1; } template <typename T1, typename T2, typename T3> pair<T1,T2> operator*(pair<T1,T2> p, T3 n) { return make_pair(p.first*n, p.second*n); } template <typename T1, typename T2, typename T3> pair<T1,T2> operator*=(pair<T1,T2>& p, T3 n) { p.first *= n; p.second *= n; return p; } template <typename T1, typename T2, typename T3> pair<T1,T2> operator/(pair<T1,T2> p, T3 n) { return make_pair(p.first/n, p.second/n); } template <typename T1, typename T2, typename T3> pair<T1,T2> operator/=(pair<T1,T2>& p, T3 n) { p.first /= n; p.second /= n; return p; }