theoretically this would compile for 'infinite' time because the template expansion is infinitely recursive:
template <size_t N>
struct eat
{
static constexpr size_t value = eat<N+1>::value;
};
However, all the compilers I have used defend against this kind of code, emitting an error much like this:
/Users/richardh/Documents/dev/Scratchpad/tryit/tryit/words.cpp:136:37: fatal error: recursive template instantiation exceeded maximum depth of 256
static constexpr size_t value = eat<N+1>::value;
^
/Users/richardh/Documents/dev/Scratchpad/tryit/tryit/words.cpp:136:37: note: in instantiation of template class 'eat<257>' requested here
static constexpr size_t value = eat<N+1>::value;
^
/Users/richardh/Documents/dev/Scratchpad/tryit/tryit/words.cpp:136:37: note: in instantiation of template class 'eat<256>' requested here
static constexpr size_t value = eat<N+1>::value;
^
/Users/richardh/Documents/dev/Scratchpad/tryit/tryit/words.cpp:136:37: note: in instantiation of template class 'eat<255>' requested here
static constexpr size_t value = eat<N+1>::value;
^
/Users/richardh/Documents/dev/Scratchpad/tryit/tryit/words.cpp:136:37: note: in instantiation of template class 'eat<254>' requested here
static constexpr size_t value = eat<N+1>::value;
...etc
EDIT:
ok, I think this one really is infinite:
template <class T>
struct eat2
{
using inner = eat2<eat2<T>>;
static constexpr int value() {
return inner::value();
}
};
int main()
{
eat2<int> e;
cout << e.value() << endl;
return 0;
}