Skip to content

Instantly share code, notes, and snippets.

@akarpov89
Last active August 29, 2015 14:07
Show Gist options
  • Save akarpov89/f2d8c5b4c043a8870831 to your computer and use it in GitHub Desktop.
Save akarpov89/f2d8c5b4c043a8870831 to your computer and use it in GitHub Desktop.
Infinite recursion during compile expansion
template <unsigned n>
unsigned fact()
{
if (n == 0)
return 1;
// return n * fact<n - 1>(); <-- not compiles, infinite recursion
return n * fact<n - (n ? 1 : 0)>(); // OK
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment