2003-12-26 Guilhem Lavaux <guilhem@kaffe.org>
[official-gcc.git] / gcc / testsuite / g++.dg / template / non-type1.C
blob70e81d362bafe1a7ccbfffa76e3228bbc52dcb7b
1 // PR c++/4377
3 template < int I1, int I2 >
4 class unit
6 public:
7   typedef unit<I1,I2> my_type;
9   unit() {}
10   unit( const unit<I1,I2>& ) {}
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    }
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   }
23 // specialization added to first test
25 template <>
26 class unit<0,0> {
27 public:
28   typedef unit<0,0> my_type;
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    }
42 int main()
44   const unit<1,0> u1;
45   const unit<2,0> u2;
47   unit<-1,0> u3( u1 / u2 );
48   unit< 3,0> u4( u1 * u2 );