title: C++11 initialize array with uniform value in constexpr function
body: <p>I have a class template which builds a simple array based on the template parameters as one of its members.  I need to be able to initialize every element in the array to a single value in one of the constructors.  Unfortunately this constructor must be <code>constexpr</code>.</p>
  
  <p>The relevant part boils down to:</p>
  
  <pre><code>template &lt;typename T, size_t N&gt;
  class foo
  {
    T data[N];
  
    constexpr foo(T val)
    {
      // initialize data with N copies of val
    }
  };
  </code></pre>
  
  <p>Using <code>std::fill</code> or a loop is incompatible with the <code>constexpr</code> requirement.  Initializing with <code>: data{val}</code> only sets the first element of the array and zero-initializes the remainder.</p>
  
  <p>How can this be achieved?</p>
  
  <p>I feel like there should be a solution with variadic templates and tuples etc...</p>