title: How to initialize static array from std::integer_sequence?
body: <p>I made an iterable generator for enums that conform with the following rules:</p>
  
  <ul>
  <li>Enum is an integer sequence, there are no gaps</li>
  <li>Given last element of the enum is not an actual enum element</li>
  </ul>
  
  <p>The class looks like this:</p>
  
  <pre><code>template &lt;typename EnumType, EnumType LENGTH&gt;
  class EnumArrayNonStatic
  {
  public:
    using ValueType = typename std::underlying_type&lt;EnumType&gt;::type;
    //! Initialize values via private constructor
    constexpr EnumArrayNonStatic() : EnumArrayNonStatic(std::make_integer_sequence&lt;ValueType, (ValueType)LENGTH&gt;{}) {}
  
    //! All values generated via std::integer_sequence
    EnumType values[(int)LENGTH];
  private:
    //! Private constructor that populates values
    template &lt;int... Indices&gt;
    constexpr EnumArrayNonStatic(std::integer_sequence&lt;int, Indices...&gt;) : values{(static_cast&lt;EnumType&gt;(Indices))...} {}
  };
  </code></pre>
  
  <p>Usage:</p>
  
  <pre><code>enum class TestEnum
  {
    A,
    B,
    C,
    D,
    LENGTH
  };
  int main()
  {
    for (const TestEnum val : EnumArrayNonStatic&lt;TestEnum, TestEnum::LENGTH&gt;().values)
    {
      std::cout &lt;&lt; (int)val &lt;&lt; "\n";
    }
    return 0;
  }
  </code></pre>
  
  <p>However, I would instead like to be able to use <code>EnumArray&lt;TestEnum, TestEnum::LENGTH&gt;::values</code> and have the values generated via template during compilation. I wrote this:</p>
  
  <pre><code>template &lt;typename EnumType, EnumType LENGTH&gt;
  class EnumArray
  {
  private:
    using ValueType = typename std::underlying_type&lt;EnumType&gt;::type;
    //! Static generator of value array (returns EnumType[])
    template &lt;ValueType... Indices&gt;
    static constexpr auto GenerateArray(std::integer_sequence&lt;ValueType, Indices...&gt;) { return {(static_cast&lt;EnumType&gt;(Indices))...}; }
  public:
    //! Static array of values of an enum
    static constexpr EnumType values[static_cast&lt;ValueType&gt;(LENGTH)] = GenerateArray(std::make_integer_sequence&lt;ValueType, static_cast&lt;ValueType&gt;(LENGTH) &gt;{});
  };
  </code></pre>
  
  <p>I've been messing around with the code for a while but I always keep getting errors. The version above prints:</p>
  
  <pre><code>1&gt;enumiteratortest.cpp(22): error C3108: cannot deduce a type as an initializer list is not an expression
  1&gt;enumiteratortest.cpp(25): note: see reference to function template instantiation 'auto EnumArray&lt;TestEnum,TestEnum::LENGTH&gt;::GenerateArray&lt;0,1,2,3&gt;(std::integer_sequence&lt;int,0,1,2,3&gt;)' being compiled
  1&gt;enumiteratortest.cpp(52): note: see reference to class template instantiation 'EnumArray&lt;TestEnum,TestEnum::LENGTH&gt;' being compiled
  1&gt;enumiteratortest.cpp(22): error C2440: 'return': cannot convert from 'initializer list' to 'auto'
  1&gt;enumiteratortest.cpp(22): note: There is no context in which this conversion is possible
  1&gt;enumiteratortest.cpp(25): error C2440: 'initializing': cannot convert from 'void' to 'const EnumType [4]'
  1&gt;        with
  1&gt;        [
  1&gt;            EnumType=TestEnum
  1&gt;        ]
  1&gt;enumiteratortest.cpp(25): note: There are no conversions to array types, although there are conversions to references or pointers to arrays
  </code></pre>
  
  <p>Surely there must be a way to initialize the array statically. Is the <code>GenerateArray</code> even necessary? Isn't there a way to do this?</p>
  
  <pre><code>int myArray[] = std::integer_sequence&lt;ValueType, Indices...&gt;{Indices...}
  </code></pre>
  
  <p>Or something along the lines?</p>