title: Are C++11+ compilers smart enough to optimize inner "if" statements?
body: <p>This is best described with code:</p>
  <pre><code>void foo(vector&lt;vector&lt;int&gt;&gt;&amp; a, vector&lt;vector&lt;int&gt;&gt;&amp; b, bool flag) { 
  
      vector&lt;vector&lt;int&gt;&gt; c; 
      for (int i ...) { 
          for (int j ...) { 
              int value; 
              if (flag) 
                  value = a[i][j] + b[i][j]; 
              else 
                  value = a[i][j] - b[i][j];
          } 
  
      } 
  } 
  </code></pre>
  <p>At face value, the flag is evaluated and branched on every single inner loop, despite being known before either loop. Will a C++11+ compiler generate two separate code paths, evaluating the branch at the beginning, or should this be manually done?</p>
  <p>Before lecturing me on premature optimization, please understand this is asked in an effort to be a more cognizant programmer regarding minor details.</p>