title: Generating a template pack
body: <p><code>Generate&lt;P&lt;3&gt;, P&lt;5,0&gt;, P&lt;4,0,0&gt;, P&lt;3,0,1&gt;&gt;::type</code> is to be</p>
  
  <pre><code>Pack&lt; A&lt;0&gt;, A&lt;0,0&gt;, A&lt;0,0,0&gt;, A&lt;0,0,1&gt;, A&lt;0,0,2&gt;, A&lt;0,0,3&gt;, A&lt;0,1&gt;, A&lt;0,1,0&gt;, A&lt;0,1,1&gt;, A&lt;0,1,2&gt;, A&lt;0,2&gt;, A&lt;0,3&gt;, A&lt;0,4&gt;, A&lt;1&gt;, A&lt;2&gt; &gt;
  </code></pre>
  
  <p>because <code>P&lt;3&gt;</code> means that <code>P&lt;n&gt;</code> exists for n = 0,1,2;  <code>P&lt;5,0&gt;</code> means that <code>A&lt;0,n&gt;</code> exists for n = 0,1,2,3,4;  <code>P&lt;4,0,0&gt;</code> means that <code>A&lt;0,0,n&gt;</code> exists for n = 0,1,2,3;  and <code>P&lt;3,0,1&gt;</code> means that <code>A&lt;0,1,n&gt;</code> exists for n = 0,1,2.
  In terms of ordering, <code>A&lt;n1,n2,n3,...,nk,x,...&gt;</code> will always precede <code>A&lt;n1,n2,n3,...,nk,y,...&gt;</code> if x &lt; y and <code>A&lt;n1,n2,n3,...,nk&gt;</code> will always precede <code>A&lt;n1,n2,n3,...,nk, ...&gt;</code>, where the second elipses ... is non-empty.
  So I need to write out the implementation of <code>Generate&lt;Packs...&gt;</code>.</p>
  
  <p>Motivation for this:  If <code>template &lt;int... Is&gt; class Object</code> has certain possibilities for its <code>Is...</code> pack, defined by constants like the 3, 5, 4, and 3 above, then a pack of all of its possible types will allow
  generation of specific <code>Object&lt;Is...&gt;</code> instances by iterating through the pack.</p>
  
  <p>Here is what I have so far:</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;type_traits&gt;
  
  template &lt;int...&gt; class A;
  template &lt;typename...&gt; struct Pack;
  template &lt;int...&gt; struct P;
  
  template &lt;int N, int Count, typename Front, typename Output&gt; struct GenerateHelper;
  
  template &lt;int N, int Count, int... Is, typename... As&gt;
  struct GenerateHelper&lt;N, Count, P&lt;Is...&gt;, Pack&lt;As...&gt;&gt; :
      GenerateHelper&lt;N, Count + 1, P&lt;Is...&gt;, Pack&lt;As..., A&lt;Is..., Count&gt;&gt;&gt; {};
  
  template &lt;int N, int... Is, typename... As&gt;
  struct GenerateHelper&lt;N, N, P&lt;Is...&gt;, Pack&lt;As...&gt;&gt; {
      using type = Pack&lt;As...&gt;;
  };
  
  template &lt;typename...&gt; struct Generate;
  
  // Simple special case just to start off.  Generate has only one pack to deal with.
  template &lt;int N, int... Is&gt;
  struct Generate&lt;P&lt;N, Is...&gt;&gt; : GenerateHelper&lt;N, 0, P&lt;Is...&gt;, Pack&lt;&gt;&gt; {};
  
  int main() {
      using T = Generate&lt;P&lt;3,0,0&gt;&gt;::type;
      std::cout &lt;&lt; std::is_same&lt;T, Pack&lt;A&lt;0,0,0&gt;, A&lt;0,0,1&gt;, A&lt;0,0,2&gt;&gt;&gt;::value &lt;&lt; '\n'; // true
  }
  </code></pre>
  
  <p>But now I'm stuck with the case of just 2 packs in Generate.  Can anyone help me continue?</p>
  
  <p>Idea:  For 2 packs, just generate separately, merge the two <code>Pack</code>s, and then sort after?  But then the sorting will be the hardest part I think.</p>