title: Change boolean flags into template arguments
body: <p>Suppose I have a versatile function with about four boolean flags:</p>
  
  <pre><code>int do_something(int arg, bool flag1, bool flag2, bool flag3, bool flag4) {
    for(int i = 0; i &lt; 1000000; i++) {
      if(flag1)
        // Do something 1
      if(flag2)
        // Do something 2
      if(flag3)
        // Do something 3
      if(flag4)
        // Do something 4
      //Do something else 5
    }
  }
  </code></pre>
  
  <p>But I don't want to incur any costs for branching on these flags in the inner loop so I change them to templates (allowing the compiler to optimize away the conditionals):</p>
  
  <pre><code>template&lt;bool flag1, bool flag2, bool flag3, bool flag4&gt;
  int do_something_helper(int arg) {
    for(int i = 0; i &lt; 1000000; i++) {
      if(flag1)
        // Do something 1
      if(flag2)
        // Do something 2
      if(flag3)
        // Do something 3
      if(flag4)
        // Do something 4
      //Do something else 5
    }
  }
  </code></pre>
  
  <p>How can I write the do_something method now?  The only way I know is as follows:</p>
  
  <pre><code>int do_something(int arg, bool flag1, bool flag2, bool flag3, bool flag4) {
      if(flag1) {
        if(flag2) {
          if(flag3) {
            if(flag4) {
              return do_something_helper&lt;true,true,true,true&gt;(arg);
            }else{
              return do_something_helper&lt;true,true,true,false&gt;(arg);
            }
          }else{
            if(flag4) {
              return do_something_helper&lt;true,true,false,true&gt;(arg);
            }else{
              return do_something_helper&lt;true,true,false,false&gt;(arg);
            }
          }
        //... You get the picture
  }
  </code></pre>
  
  <p>Is there some way to get the compiler to write the above code automatically so I don't have to include this ugly monstrosity in my beautiful code-base?</p>