title: Refactor constant expression if statement in template function
body: <p>I'd like to refactor the following code:</p>
  
  <pre><code>enum Mode { None, Value1, Value2 }
  template &lt;Mode mode&gt;
  bool func() {
      if (mode == None) {
          helperNone();
          return funcImplNone();
      } else if (mode == Value1) {
          helper1();
          return funcImplValue1();
      } else if (mode == Value2) {
          helper2(); 
          return funcImplValue2();
      }
      return true;
  }
  </code></pre>
  
  <p>because the expression </p>
  
  <pre><code>mode == None 
  </code></pre>
  
  <p>is computed during a compile time. And also can't thhis code lead to a code bloat (code duplication in an executable file)?</p>
  
  <p>I'm thinking of the following refactoring:</p>
  
  <pre><code>template&lt;Mode&gt;
  bool func() {
      return true;
  }
  
  template&lt;&gt;
  bool func&lt;None&gt;() {
      return true;
  }
  
  template&lt;&gt;
  bool func&lt;Value1&gt;() {
      helper1();
      return funcImplValue2();
  }
  
  template&lt;&gt;
  bool func&lt;Value2&gt;() {
      helper2();
      return funcImplValue2();
  }
  </code></pre>
  
  <p>Is there any other standard way  to refactor that?
  Do we have guarantees that compiler will optimize that code itself?
  Doesn't the refactored code looks more clear?</p>