1// PR c++/4377 2 3template < int I1, int I2 > 4class unit 5{ 6public: 7 typedef unit<I1,I2> my_type; 8 9 unit() {} 10 unit( const unit<I1,I2>& ) {} 11 12 template< int Q1, int Q2 > 13 unit< I1 + Q1, I2 + Q2 > operator * ( const unit< Q1, Q2 >& rhs ) const { 14 return unit< I1 + Q1, I2 + Q2 >(); 15 } 16 17 template< int Q1, int Q2 > 18 unit< I1 - Q1, I2 - Q2 > operator / ( const unit< Q1, Q2 >& rhs ) const { 19 return unit< I1 - Q1, I2 - Q2 >(); 20 } 21}; 22 23// specialization added to first test 24// 25template <> 26class unit<0,0> { 27public: 28 typedef unit<0,0> my_type; 29 30 unit() {} 31 32 friend unit<0,0> operator*( const unit<0,0>& lhs, const unit<0,0>& rhs ) { 33 return unit<0,0>(); 34 } 35 friend unit<0,0> operator/( const unit<0,0>& lhs, const unit<0,0>& rhs ) { 36 return unit<0,0>(); 37 } 38 39}; 40 41 42int main() 43{ 44 const unit<1,0> u1; 45 const unit<2,0> u2; 46 47 unit<-1,0> u3( u1 / u2 ); 48 unit< 3,0> u4( u1 * u2 ); 49} 50