title: Constructing a type using parameter pack of types and an input array of corresponding values
body: <p>Before posting this question, I have already tried to fit the approaches mentioned over <a href="https://stackoverflow.com/questions/7858817/unpacking-a-tuple-to-call-a-matching-function-pointer?lq=1">here</a>, <a href="https://stackoverflow.com/questions/31054068/c-convert-a-parameter-pack-of-types-to-parameter-pack-of-indices">here</a> and <a href="https://stackoverflow.com/questions/34951058/transform-a-variadic-pack-of-types-into-values">here</a>. However, nothing could solve my requirement as I have an intermediate function that needs some adjustments.</p>
  
  <p>Essentially,what I have is as follows. I have to construct the type <code>T</code> based on the arguments whose types are stored in parameter pack <code>Args</code> and corresponding values in the array <code>ARGValue *ptr</code></p>
  
  <p>However, to map the values of type from <code>ARGValue* ptr</code> to a type in <code>Args...</code>
  I need to do an intermediate operation which is as below. </p>
  
  <pre><code>    // Specialization for 1 argument
  
          template&lt;typename T,typename... Args&gt;
          struct instance_helper&lt;T,1,Args...&gt;
          {   
              static T invokeConstructor(const ARGValue *ptr)
              {   
                  // Intermediate operation
                  typedef typename std::tuple_element&lt;0, std::tuple&lt;Args...&gt; &gt;::type TT;
                  const auto val0 = *(someUglyCast&lt;TT*&gt;(ptr[0])) ;
  
                  // Return the desired type 
                  return T(val0);
              }
          };
  
       //Specialization for no argument
  
          template&lt;typename T,typename... Args&gt;
          struct instance_helper&lt;T,0,Args...&gt;
          {   
              static T invokeConstructor(const ARGValue*)
              {   
                  return T(); 
              }   
          };  
  
       // General Case
          template&lt;typename T,size_t packSize,typename... Args&gt;
          struct instance_helper
          {   
              static T invokeConstructor(const ARGValue *ptr)
              {             
                  // Do some recursive magic here for intermediate operation
                  return T(//Do some recursive magic) ;
              }   
          };  
  </code></pre>
  
  <p>How do I solve this? How can I safely get the values for all the types in <code>Args...</code> from <code>ARGValue*</code> and then construct the type <code>T</code>? </p>
  
  <p>I do not want to create specializations for multiple arguments as it might clutter the code.</p>