title: Recursive template metaprogramming
body: <p>For calculating factorial I can use :</p>
  
  <pre><code>template&lt;int N&gt; struct factorial { enum { value = N * factorial&lt;N-1&gt;::value }; };
  
  template&lt;&gt; struct factorial&lt;1&gt; { enum { value = 1 }; }; //base Case
  </code></pre>
  
  <p>and then can use it like following</p>
  
  <p><code>x=factorial&lt;8&gt;::value;</code></p>
  
  <p>So, is it possible to get similar recursive template for </p>
  
  <pre><code> unsigned Log2(unsigned n, unsigned p = 0) {
      return (n &lt;= 1) ? p : Log2(n / 2, p + 1);
  }
  </code></pre>
  
  <p>I can think of this:</p>
  
  <pre><code>template&lt;int N,unsigned int P=0&gt; struct Log2 
      { enum { value = Log2&lt;N/2,P+1&gt;::value }; };
  </code></pre>
  
  <p>But don't know how to set a base case.</p>
  
  <pre><code> template&lt;&gt; struct Log2&lt;0,???&gt; { enum { value = ???? }; };
  </code></pre>
  
  <p>Any ideas ?</p>