title: recursive template instantiation exceeded maximum depth of 256
body: <p>I was trying to rewrite the Factorial implementation using <code>constexpr</code> function but for some reason I have no idea why I get a compile error:</p>
  
  <blockquote>
    <p>recursive template instantiation exceeded maximum depth of 256</p>
  </blockquote>
  
  <p>Actually I know what the error message means but what I don't is why I'm getting this error and why the code 1 using <code>struct</code> work but the second using function doesn't. What's the difference between them?</p>
  
  <pre><code> // yes, I know it doesn't return the factorial value. First I want to make it compile
  template &lt;int N&gt;
  constexpr int f2()
  {
      return N == 0 ? 1 : f2&lt;N - 1&gt;();
  }
  
  template &lt;int N&gt; struct Factorial
  {
      enum 
      {
          value = N * Factorial&lt;N - 1&gt;::value
      };
  };
  
  template &lt;&gt; struct Factorial&lt;0&gt;
  {
      enum
      {
          value = 1
      };
  };
  
  
  int main() 
  {
      x = f2&lt;4&gt;(); // compile error
      n = Factorial&lt;4&gt;::value; // works fine
  }
  </code></pre>