title: Will the compiler unroll this loop?
body: <p>I am creating a multi-dimensional vector (mathematical vector) where I allow basic mathematical operations +,-,/,*,=. The template takes in two parameters, one is the type (int, float etc.) while the other is the size of the vector. Currently I am applying the operations via a for loop. Now considering the size is known at compile time, will the compiler unroll the loop? If not, is there a way to unroll it with no (or minimal) performance penalty?</p>
  
  <pre><code>template &lt;typename T, u32 size&gt;
  class Vector
  {
  public:
      // Various functions for mathematical operations. 
      // The functions take in a Vector&lt;T, size&gt;.
      // Example:
      void add(const Vector&lt;T, size&gt;&amp; vec)
      {
          for (u32 i = 0; i &lt; size; ++i)
          {
              values[i] += vec[i];
          }
      }
  
  private:
      T   values[size];
  };
  </code></pre>
  
  <p>Before somebody comments <code>Profile then optimize</code> please note that this is the basis for my 3D graphics engine and it must be fast. Second, I want to know for the sake of educating myself.</p>