title: Assembling a compile-time list of types one by one (C++)
body: <p>I want to assemble a list (actually: a set) of types at compile-time by adding types one by one. Something like this:</p>
  
  <pre><code>struct HeadOfList;
  
  struct Item1;
  [ addToList&lt;Item1, HeadOfList&gt; ]
  
  struct Item2;
  [ addToList&lt;Item2, HeadOfList&gt; ]
  </code></pre>
  
  <p>I do not care how the list is stored. I think of something like this:</p>
  
  <pre><code>template&lt;typename T&gt; struct NextInList { typedef void type; };
  template&lt;&gt; struct NextInList&lt;HeadOfList&gt; { typedef Item1 type; };
  template&lt;&gt; struct NextInList&lt;Item1&gt; { typedef Item2 type; };
  template&lt;&gt; struct NextInList&lt;Item2&gt; { typedef Item3 type; };
  </code></pre>
  
  <p>but a <code>boost::mpl::list</code> is just as fine. The order of the types does not matter either, I just want to be able to iterate through them and adding new elements to them.</p>
  
  <p>I have a bad feeling about this, since such a construction would mean that e.g. <code>LastElementOf&lt;MyList&gt;::type</code> would compile to different types at different points of the source file (before and after adding a new element), and it seems bogus to me. Nevertheless that is exactly what I want now.</p>
  
  <p>Do you think it is possible somehow? C++11 is allowed.</p>
  
  <p><strong>Update:</strong> I just want to add that I do not know the last element added to the list at the time of adding a new element, but I know the list itself (e.g. the head of the list)</p>