title: Variadic Dispatch Function
body: <p>I have an interface wherein the types of the parameters mostly encode their own meanings.  I have a function that takes one of these parameters.  I'm trying to make a function that takes a set of these parameters and performs the function on each one in order.</p>
  
  <pre class="lang-cpp prettyprint-override"><code>#include &lt;iostream&gt;
  #include &lt;vector&gt;
  
  enum param_type{typeA,typeB};
  
  template &lt;param_type PT&gt; struct Container{
    int value;
    Container(int v):value(v){}
  };
  
  int f(Container&lt;typeA&gt; param){
    std::cout&lt;&lt;"Got typeA with value "&lt;&lt;param.value&lt;&lt;std::endl;
    return param.value;
  }
  int f(Container&lt;typeB&gt; param){
    std::cout&lt;&lt;"Got typeB with value "&lt;&lt;param.value&lt;&lt;std::endl;
    return param.value;
  }
  </code></pre>
  
  <p>My current solution uses a recursive variadic template to delegate the work.</p>
  
  <pre class="lang-cpp prettyprint-override"><code>void g(){}
  template &lt;typename T,typename...R&gt;
  void g(T param,R...rest){
    f(param);
    g(rest...);
  }
  </code></pre>
  
  <p>I would like to use a packed parameter expansion, but I can't seem to get that to work without also using the return values. (In my particular case the functions are void.)</p>
  
  <pre class="lang-cpp prettyprint-override"><code>template &lt;typename...T&gt; // TODO: Use concepts once they exist.
  void h(T... params){
    // f(params);...
    // f(params)...;    // Fail to compile.
    // {f(params)...};
    std::vector&lt;int&gt; v={f(params)...}; // Works
  }
  </code></pre>
  
  <p>Example usage</p>
  
  <pre class="lang-cpp prettyprint-override"><code>int main(){
    auto a=Container&lt;typeA&gt;(5);
    auto b=Container&lt;typeB&gt;(10);
    g(a,b);
    h(a,b);
    return 0;
  }
  </code></pre>
  
  <p>Is there an elegant syntax for this expansion in C++?</p>