title: Access a type in a variadic template by index
body: <p>I would like to obtain a type in a variadic template by index. The index is specified as a template argument.
  I managed to find a 'hack' that works, but I believe that it is not in the spirit of variadic template programming. Besides, it uses extra memory. </p>
  
  <p>Here is the code with some explanations:</p>
  
  <pre><code>template &lt;typename... InputPortTypes&gt;
  class PipelineReceiver
  {
  
  protected:
  
      // This tuple is used for storing types only
      // Hence, I would like to get rid of it, but I am not sure how.
      std::tuple&lt;
      std::function&lt;std::unique_ptr&lt;InputPortTypes&gt; (int)&gt;...
      &gt; InputPortsTuple;
  
      // This vector is used for storing the actual objects
      // This is needed to be able to access/change its elements
      // during run time later on.
      // The vector is used for storage of function pointers (i.e. of type std::function)
      // that represent methods of another object upstream the pipeline.
      std::vector&lt;boost::any&gt; InputPortsVector;
  
  public:
  
      PipelineReceiver()
          {
              // create an empty vector of the required size
              InputPortsVector.resize(sizeof...(InputPortTypes));
          }
  
      void connectPorts(int InputPortIndex, boost::any c_OutputPort)
          {
              // connect ports
              InputPortsVector[InputPortIndex] = c_OutputPort;
          }
  
       // this function needs to be modified to avoid using InputPortsTuple
      template&lt;int N&gt;
      void getInputPortValue(void)
          {
              std::cout &lt;&lt;
                  *boost::any_cast&lt;decltype(std::get&lt;N&gt;(this -&gt; InputPortsTuple))&gt;(
                      InputPortsVector[N]
                      )(0) &lt;&lt;
                  std::endl;
          }
  
  };
  </code></pre>
  
  <p>I would like to remove the object <code>InputPortsTuple</code> and replace it with some form of a recursive procedure for inferring the types in <code>getInputPortValue</code>. </p>
  
  <p>Ideally, I would like <code>N</code> to be a dynamic parameter instead of a template argument. However, I am not sure if this is possible.</p>