title: Templating Structs to Combine Enums
body: <p>I am currently doing a project that requires me to aggregate multiple enums to one huge enum. I could just write it, but managing one would be troublesome. I have an idea of using structs to wrap around the different enums and templating, the parameter would be an integer, for example:</p>
  
  <pre><code>template &lt;int START&gt;
  struct first_enum
  {
      enum constant
      {
          a = START, 
          b, c, d
      };
  
      static constexpr int end() { return d; }
  }
  
  template &lt;int START&gt;
  struct second_enum
  {
      enum constant
      {
          e = START, 
          f
      };
  
      static constexpr int end() { return f; }
  }
  
  template &lt;int START&gt;
  struct third_enum
  {
      enum constant
      {
          g = START, 
          h
      };
  
      static constexpr int end() { return h; }
  }
  </code></pre>
  
  <p>Then I have another struct that inherits from the previous structs:</p>
  
  <pre><code>struct enum_all : public first_enum&lt;0&gt;,
                           second_enum&lt;first_enum&lt;0&gt;::end() + 1&gt;,
                           third_enum&lt;second_enum&lt;first_enum&lt;0&gt;::end() + 1&gt;::end() + 1&gt; {};
  </code></pre>
  
  <p>This way <code>enum_all</code> will have members <code>a</code>, <code>b</code>, <code>c</code>, ..., <code>h</code> with values ranging from 0...7.</p>
  
  <p>However writing that down is very cumbersome and not scalable (imagine adding more structs).</p>
  
  <p>I suspect you could do this using variadic templates, however I am still a beginner with template metaprogramming. Here is what I currently have for a base case and it compiles.</p>
  
  <pre><code>template &lt;int START, template&lt;int&gt; typename ENUM&gt;
  struct enum_all_t : public ENUM&lt;START&gt;
  {
  
  };
  </code></pre>
  
  <p>Calling <code>enum_all_t&lt;0, first_enum&gt;::a</code> gives me the correct result. I tried adding another template specialization, but it tells me "error: redeclared with 3 template parameters". </p>
  
  <pre><code>template &lt;int START, template &lt;int&gt; typename ENUM, template &lt;int&gt; typename... ENUMS&gt;
  struct enum_all_t : public ENUM&lt;START&gt;, enum_all_t&lt;ENUM&lt;START&gt;::end() + 1, ENUMS&gt; {};
  </code></pre>