Добрый день!
Хочу добиться статического преобразования enum в порядковый номер элемента в этом самом enum. Компилятор вылетает по ошибке:
class Foo {
public:
enum X {
EL1 = 134,
EL2 = 10,
EL3 = 487
};
const static Foo::X TRX[3];
};
const Foo::X Foo::TRX[3] = {Foo::EL1,Foo::EL2,Foo::EL3};
void func(Foo::X);
inline Foo::X I2X(int i) { return Foo::TRX[i]; }
template <Foo::X x, int i> struct X2IT{ enum {value = (i == -1) ? -1 : ((x == I2X(i)) ? i : X2IT<x,i-1>::value)}; };
template <Foo::X x> struct X2I { enum {value = X2IT<x,sizeof(Foo::TRX)/sizeof(Foo::X)-1>::value};};
int _tmain(int argc, _TCHAR* argv[])
{
cout << X2I<Foo::EL3>::value; // здесь ошибка
return 0;
}
ошибка:
1>.\SS.cpp(27) : fatal error C1001: An internal error has occurred in the compiler.
1>(compiler file 'msc1.cpp', line 1392)
1> To work around this problem, try simplifying or changing the program near the locations listed above.
1>Please choose the Technical Support command on the Visual C++
1> Help menu, or open the Technical Support help file for more information
1> .\SS.cpp(27) : see reference to class template instantiation 'X2IT<x,i>' being compiled
1> with
1> [
1> x=EL3,
1> i=-492
1> ]
1> .\SS.cpp(27) : see reference to class template instantiation 'X2IT<x,i>' being compiled
1> with
1> [
1> x=EL3,
1> i=-491
1> ]
1> .... и так далее
т.е. компилятор пытается раскрыть всё глубже и глубже template. Как его остановить

?
Павел