title: C++ evaluate constexpr template array values at compile time
body: <p>I'm creating an array of packed chars at compile time, but c++ is telling me that the expression must have a constant value -- cannot evaluate value of incomplete "gradient&lt;256U>".</p>
  
  <p>I'm trying to embed a color gradient inside my code from code.</p>
  
  <pre class="lang-cpp prettyprint-override"><code>template&lt;unsigned S&gt;
  struct gradient {
    constexpr gradient() : arr() {
      for (auto i = 0; i &lt; S; i++)
        for (auto j = 0; j &lt; S; j++)
          arr[i + j * S] = ((i % 256) &lt;&lt; 24) | ((j % 256) &lt;&lt; 16) | (((i * j) % 256) &lt;&lt; 8) | 255;
    }
  
    unsigned arr[S * S];
  };
  
  constexpr auto g0 = gradient&lt;255&gt;(); // ok
  constexpr auto g1 = gradient&lt;256&gt;(); // error
  constexpr auto g2 = gradient&lt;1024&gt;(); // error
  </code></pre>
  
  <p>All of a sudden I can't create my gradient struct with higher values then 255. But why?</p>