title: Insert/remove type into variadic template list (parameter pack)
body: <p>What is the best way of implementing index-based insertion and deletion of a type in a variadic template type list (parameter pack)?</p>
  
  <p>Desired code/behavior:</p>
  
  <pre><code>template&lt;typename...&gt; struct List { /* ... */ };
  
  static_assert(is_same
  &lt;
      List&lt;int, char, float&gt;::Insert&lt;int, 0&gt;,
      List&lt;int, int, char, float&gt;
  &gt;());
  
  static_assert(is_same
  &lt;
      List&lt;int, char, float&gt;::Insert&lt;int, 2&gt;,
      List&lt;int, char, int, float&gt;
  &gt;());
  
  static_assert(is_same
  &lt;
      List&lt;int, char, float&gt;::Remove&lt;0&gt;,
      List&lt;char, float&gt;
  &gt;());
  
  static_assert(is_same
  &lt;
      List&lt;int, char, float&gt;::Remove&lt;1&gt;,
      List&lt;int, float&gt;
  &gt;());
  </code></pre>
  
  <p>I tried an implementation based on pushing back the arguments in an initially-empty list, but it was very hard to read/maintain. The parameters were similar to this:</p>
  
  <pre><code>template&lt;typename T, int I, int ITarget, typename TResult&gt; struct InsertImpl;
  </code></pre>
  
  <p>I constantly increment <code>I</code> until it equals <code>ITarget</code>, pushing back existing types in <code>TResult</code>, which is a <code>List&lt;...&gt;</code>. When <code>I</code> equals <code>ITarget</code>, I push back <code>T</code> in <code>TResult</code> as well.</p>
  
  <p>Removing a type had a similar implementation - instead of pushing back twice when the indices were equal, I simply skipped the type.</p>
  
  <p>My cumbersome solution would implement insertion and removal in terms of pushing and popping. I believe it would be more elegant to have pushing to the front equal to <code>Insert&lt;0&gt;</code> and pushing to the back equal to <code>Insert&lt;size&gt;</code>. The same applies for popping from the front and from the back.</p>
  
  <p><strong>Is there a better way of doing this? Could C++14 features help?</strong></p>