title: How can I iterate over a packed variadic template argument list?
body: <p>I'm trying to find a method to iterate over an a pack variadic template argument list.
  Now as with all iterations, you need some sort of method of knowing how many arguments are in the packed list, and more importantly how to individually get data from a packed argument list.</p>
  
  <p>The general idea is to iterate over the list, store all data of type int into a vector, store all data of type char* into a vector, and store all data of type float, into a vector. During this process there also needs to be a seperate vector that stores individual chars of what order the arguments went in.  As an example, when you push_back(a_float), you're also doing a push_back('f') which is simply storing an individual char to know the order of the data.  I could also use a std::string here and simply use +=.  The vector was just used as an example.</p>
  
  <p>Now the way the thing is designed is the function itself is constructed using a macro, despite the evil intentions, it's required, as this is an experiment.  So it's literally impossible to use a recursive call, since the actual implementation that will house all this will be expanded at compile time; and you cannot recruse a macro.</p>
  
  <p>Despite all possible attempts, I'm still stuck at figuring out how to actually do this.  So instead I'm using a more convoluted method that involves constructing a type, and passing that type into the varadic template, expanding it inside a vector and then simply iterating that.  However I do not want to have to call the function like:</p>
  
  <pre><code>foo(arg(1), arg(2.0f), arg("three");
  </code></pre>
  
  <p>So the real question is how can I do without such?  To give you guys a better understanding of what the code is actually doing, I've pasted the optimistic approach that I'm currently using.</p>
  
  <pre><code>struct any {
    void do_i(int   e) { INT    = e; }
    void do_f(float e) { FLOAT  = e; }
    void do_s(char* e) { STRING = e; }
  
    int   INT;
    float FLOAT;
    char *STRING;
  };
  
  
  template&lt;typename T&gt; struct get        { T      operator()(const any&amp; t) { return T();      } };
  template&lt;&gt;           struct get&lt;int&gt;   { int    operator()(const any&amp; t) { return t.INT;    } };
  template&lt;&gt;           struct get&lt;float&gt; { float  operator()(const any&amp; t) { return t.FLOAT;  } };
  template&lt;&gt;           struct get&lt;char*&gt; { char*  operator()(const any&amp; t) { return t.STRING; } };
  
  #define def(name)                                  \
    template&lt;typename... T&gt;                          \
    auto name (T... argv) -&gt; any {                   \
     std::initializer_list&lt;any&gt; argin = { argv... }; \
      std::vector&lt;any&gt; args = argin;
  #define get(name,T)  get&lt;T&gt;()(args[name])
  #define end }
  
  any arg(int   a) { any arg; arg.INT    = a; return arg; }
  any arg(float f) { any arg; arg.FLOAT  = f; return arg; }
  any arg(char* s) { any arg; arg.STRING = s; return arg; }
  </code></pre>
  
  <p>I know this is nasty, however it's a pure experiment, and will not be used in production code.  It's purely an idea.  It could probably be done a better way.  But an example of how you would use this system:</p>
  
  <pre><code>def(foo)
    int data = get(0, int);
    std::cout &lt;&lt; data &lt;&lt; std::endl;
  end
  </code></pre>
  
  <p>looks a lot like python. it works too, but the only problem is how you call this function.
  Heres a quick example:</p>
  
  <pre><code>foo(arg(1000));
  </code></pre>
  
  <p>I'm required to construct a new any type, which is highly aesthetic, but thats not to say those macros are not either.  Aside the point, I just want to the option of doing:
      foo(1000);</p>
  
  <p>I know it can be done, I just need some sort of iteration method, or more importantly some std::get method for packed variadic template argument lists.  Which I'm sure can be done.</p>
  
  <p>Also to note, I'm well aware that this is not exactly type friendly, as I'm only supporting int,float,char* and thats okay with me.  I'm not requiring anything else, and I'll add checks to use type_traits to validate that the arguments passed are indeed the correct ones to produce a compile time error if data is incorrect.  This is purely not an issue.  I also don't need support for anything other then these POD types.</p>
  
  <p>It would be highly apprecaited if I could get some constructive help, opposed to arguments about my purely illogical and stupid use of macros and POD only types.  I'm well aware of how fragile and broken the code is.  This is merley an experiment, and I can later rectify issues with non-POD data, and make it more type-safe and useable.</p>
  
  <p>Thanks for your undertstanding, and I'm looking forward to help.</p>