title: Why give a typename template parameter a default value of 0 in C++?
body: <h2>The short version (Read if you have no patience like  me):</h2>
  
  <p>What does setting a typename template parameter to a default of 0 do in C++?</p>
  
  <p>My enable if struct:</p>
  
  <pre><code>/**
   * @brief Can be used to enable a template definition using a boolean value
   */
  template&lt;lfBool Condition&gt;
  struct lfEnableIf
  { };
  
  template&lt;&gt;
  struct lfEnableIf&lt;true&gt;
  {
     typedef lfInt Type;
  };
  </code></pre>
  
  <p>My boolen constant struct:</p>
  
  <pre><code>template&lt;lfBool Val&gt;
  struct lfBoolConstant
  {
      static const lfBool Value = Val;    
  };
  
  typedef lfBoolConstant&lt;true&gt; lfTrueType;
  typedef lfBoolConstant&lt;false&gt; lfFalseType;
  </code></pre>
  
  <p>My type trait struct (just one of the specializations):</p>
  
  <pre><code>template &lt;typename NumT&gt; struct lfIsArithmetic : lfFalseType{};
  
  template &lt;&gt; struct lfIsArithmetic&lt;lfChar&gt; : lfTrueType{};
  </code></pre>
  
  <p>And finally my usage of it all:</p>
  
  <pre><code>template&lt;typename T, typename lfEnableIf&lt;lfIsArithmetic&lt;T&gt;::Value&gt;::Type = 0&gt;
  struct Test
  {
      static void print()
      {
          std::cout &lt;&lt; "OK!" &lt;&lt; std::endl;
      }
  
  };
  
  int main()
  {
      Test&lt;lfFloat&gt;::print();
      Test&lt;lfBool&gt;::print();
  
      return 0;
  }
  </code></pre>
  
  <p>Sorry for the poor for formatting I am writing this on my cell phone.</p>
  
  <h2>The long version (Please read if you have the patience so you understand why there is not much code):</h2>
  
  <p>So, I am on vacation and don't have access to my workstation or laptop so I thought I would try out AIDE, which if you are unaware is an IDE for android that can compile C++. At home I am designing a game engine that includes Boost and I figured I would try to create something similar to the <code>enable_if</code> structures that are in the Boost.Core library. I got it mostly working but it would not compile unless I set the enable if structure in the template I was enabling to default to 0! This is what you do with the Boost <code>enable_if</code> and <code>disable_if</code> templates. So what does setting a typename template parameter to a default of 0 do in C++?</p>
  
  <p>Thanks!</p>