Append to std::array
<p>Since I was not able to find such a function (incorrectly?), I'm trying to make a compile-time function (<code>constexpr</code>) function which takes a <code>std::array&lt;T,n&gt; arr</code> and a <code>T t</code> and returns a new <code>std::array&lt;T,n+1&gt;</code> with <code>t</code> added to the end of <code>arr</code>. I've started with something like this:</p>

<pre><code>template &lt;typename T, int n&gt;
constexpr std::array&lt;T,n+1&gt; append(std::array&lt;T,n&gt; a, T t);

template &lt;typename T&gt;
constexpr std::array&lt;T,1&gt; append(std::array&lt;T,0&gt; a, T t)
{
  return std::array&lt;T,1&gt;{t};
}

template &lt;typename T&gt;
constexpr std::array&lt;T,2&gt; append(std::array&lt;T,1&gt; a, T t)
{
  return std::array&lt;T,2&gt;{a[0], t};
}
</code></pre>

<p>Here I get stuck. What I need is a way to expand <code>a</code> in the first <code>n</code> places of the initializer list, and then add <code>t</code> add the end. Is that possible? Or is there another way of doing this?</p>