Initializing a std::array from a recursive template computation I wrote this code for an answer over on SO.  I suspect it's possible to clean it up a bit, particularly the base-case specialization for FactorialArray, which is repetitive and contains odd bits (for instance: why double curly braces? because clang complains about un-braced subobject initializers otherwise...)

Any and all suggestions are appreciated.  Note that Factorial is separate from FactorialArray for pedagogical clarity; I realize this makes the compile-time calculation O(N2) unless the compiler is clever enough to memoize it.

#include &lt;iostream&gt;
#include &lt;cinttypes&gt;
#include &lt;array&gt;

using std::uint64_t;

// Helper template that computes the factorial of one integer
template&lt;uint64_t I&gt; struct Factorial
{ static constexpr uint64_t value = I * Factorial&lt;I-1&gt;::value; };

template&lt;&gt; struct Factorial&lt;0&gt; { static constexpr uint64_t value = 1; };

// FactorialArray recursively assembles the desired array as a variadic
// template argument pack from a series of invocations of Factorial
template&lt;uint64_t I, uint64_t... Values&gt; struct FactorialArray
  : FactorialArray&lt;I-1, Factorial&lt;I&gt;::value, Values...&gt;
{};

// and in the base case, initializes a std::array with that pack
template&lt;uint64_t... Values&gt; struct FactorialArray&lt;uint64_t(-1), Values...&gt;
  : std::array&lt;uint64_t, sizeof...(Values)&gt;
{
  constexpr FactorialArray()
    : std::array&lt;uint64_t, sizeof...(Values)&gt; ({{Values...}})
  {}
};

int main()
{
  static FactorialArray&lt;10&gt; f;
  for (std::size_t i = 0; i &lt; f.size(); i++)
    std::cout &lt;&lt; i &lt;&lt; "! = " &lt;&lt; f[i] &lt;&lt; '\n';
  return 0;
}
I think your code is fine for the most part. I don't like the inheritance from std::array, seeing as you can do the same thing with a static array data member, which would make the code easier to maintain (less coupling).

If you're well-and-truly in C++14 land, I think the code is clearer if you use constexpr functions rather than functions-disguised-as-structs:

#include &lt;iostream&gt;
#include &lt;utility&gt;
#include &lt;array&gt;

constexpr size_t factorial(size_t t) {
    return t == 0 ? 1 : t * factorial(t - 1);
}

template&lt;size_t... i&gt;
constexpr auto factorial_array(std::index_sequence&lt;i...&gt;) {
    return std::array&lt;size_t, sizeof...(i)&gt;{{factorial(i)...}};
}

template&lt;size_t size&gt;
constexpr auto factorial_array() {
    return factorial_array(std::make_index_sequence&lt;size&gt;{});
}

int main() {
  constexpr auto f = factorial_array&lt;15&gt;();
  for (size_t i = 0; i &lt; f.size(); i++) {
    std::cout &lt;&lt; i &lt;&lt; "! = " &lt;&lt; f[i] &lt;&lt; '\n';
  }
  return 0;
}