egcs does not support a?b:c expressions as template integer parameter

Laurent Bonnaud bonnaud@irisa.fr
Wed Jan 7 15:45:00 GMT 1998


Hi,

i noticed that gcc does not implement the following :

#include <iostream.h>

inline void g(int i)
{
  cout<<i<<endl;
}

template<int I>
class loop {
public:
  static inline void f()
  {
    g(I);
    loop<(I>0)?(I-1):0>::f(); // here is the problem
  }
};

class loop<0> {
public:
  static inline void f()
  {
    g(0);
  }
};

int main()
{
  loop<4>::f();
  return 0;
}

% g++ loop.cpp 
loop.cpp: In function `static void loop<I>::f()':
loop.cpp:14: parse error before `;'

This program compiles with some other compilers and gives this output :

4
3
2
1
0

This exemple is trivial but similar programs are very useful for
"Template Metaprograms", see :

http://monet.uwaterloo.ca/~tveldhui/papers/Template-Metaprograms/meta-art.html

Would it be difficult to implement this in gcc/egcs ?

-- 
Laurent.



More information about the Gcc mailing list