title: How do you initialize a templated class with an unknown number of constructor arguments in C++?
body: <p>For a project I'm currently working on, a nonstandard input scheme is used, and I'm trying to make a general case translator between that input scheme and actual usable data. </p>
  
  <p>The input format encodes a number of 'events', each of which has a variety of attributes. Only a small subset of attributes need to be used for any given use case, but which attributes those are varies regularly. </p>
  
  <p>To access the information on an event, you first have to initialize a number of reader objects. For an input file containing two events, the first with duration of 4 and the second with duration of 2, it would work like this:</p>
  
  <pre><code>InFileReader ifr (filename);
  Reader&lt;int&gt; durationReader ("duration", ifr);
  ifr.nextEvent();
  cout &lt;&lt; durationReader; // Prints "4"
  ifr.nextEvent(); 
  cout &lt;&lt; durationReader; // Prints "2"
  </code></pre>
  
  <p>It's fairly simple to translate an event read in through this method to an Event object of my own design; I just make a reader for each attribute I need, and emplace back the event into a vector using the readers as my initializer list. It's a pain to have to redo this for every project I create, however, so I'm trying to create a general case function that can handle this for me. Ideally, the behavior will look like this:</p>
  
  <pre><code>class Event {
    public:
      Event (int arg1, string arg2, double arg3);
  }
  
  vector&lt;Event&gt; v;
  vector&lt;string&gt; attrNames = {"duration", "name", "weight"};
  readInFile (filename, v, attrNames);
  </code></pre>
  
  <p>This snippet would initialize Reader objects to read attributes "duration", "name", and "weight", then execute a step equivalent to v.emplace_back(durationReader, nameReader, weightReader), looping until it's done so for all events. </p>
  
  <p>This isn't so hard to do for this one particular case. The issue I face is that I want it to work no matter the size of the attrNames array, or what type each of the attributes is. I can guarantee the Event object constructor will always accept the right types in the right order, but creating the proper Readers and giving them all as contructor arguments seems impossible with my current knowledge of C++.</p>
  
  <p>Any help would be greatly appreciated.</p>
  
  <p>Edit: </p>
  
  <p>A TLDR was requested. Basically, I have a mapping of some sort between string-value pairs. I want to write a function that takes a list of strings, then calls a second function by passing the associated values as arguments. </p>
  
  <p>My issue comes from the fact that I'm not sure how many strings will be passed to the function in the first place, or what the type of each associated value is. I'm not sure how to make that work. </p>