title: C++ function vs template with an integer parameter?
body: <p>Reading the Wikibook <a href="http://en.wikibooks.org/wiki/Optimizing_C%2B%2B">Optimizing C++</a>, in <a href="http://en.wikibooks.org/wiki/Optimizing_C%2B%2B/Code_optimization/Instruction_count#Template_integer_parameters">this paragraph</a> there is the following suggestion:</p>
  
  <blockquote>
    <p>If an integer value is a constant in the application code, but is a variable in library code, make it a template parameter.</p>
  </blockquote>
  
  <p>So if I have a function like</p>
  
  <pre><code>void myfunction(int param)
  {
       switch(param)
       {
            case 1:
                do_something_1();
            break;
  
            case 2:
                do_something_2();
            break; 
  
            ...
  
            case 100:                 // 100 is taken as example
                do_something_100();
            break;
       }
  }
  </code></pre>
  
  <p>Is convenient to replace it with the following?</p>
  
  <pre><code>template&lt;int param&gt; void myfunction()
  {
       switch(param)
       {
            case 1:
                do_something_1();
            break;
  
            case 2:
                do_something_2();
            break; 
  
            ...
  
            case 100:                 // 100 is taken as example
                do_something_100();
            break;
       }
  }
  </code></pre>
  
  <p>Or is completely unnecessary? Could you please explain to me the reason?</p>