title: Is double/nested variadic template expansion allowed in modern C++?
body: <p>I've been trying to use C++ metaprogramming to build constructs such as</p>
  
  <pre><code>f(g&lt;0&gt;(args...), g&lt;1&gt;(args...), ... g&lt;n-1&gt;(args...))
  </code></pre>
  
  <p>given callables <code>f</code> and <code>g</code>, integer n and variadic arguments args...</p>
  
  <p>However I turn the problem, at some point, I need a <em>nested variadic expansion</em> : one for args... and one for 0 ... n-1, and given the compilation errors I'm getting, I'm wondering if/when it's possible in C++11/14/17, and if not, if there is a clever work-around ?</p>
  
  <p>Below, and example of what I'd like to achieve:</p>
  
  <pre><code>struct add
  {
      template&lt;int n, class A, class B&gt; static inline auto
      f(const A &amp; a, const B &amp; b) -&gt; decltype(std::get&lt;n&gt;(a)+b)
          { return std::get&lt;n&gt;(a) + b; }
  };
  
  template&lt;class... Args&gt; void do_stuff(const Args &amp; ... args)
      { /* do stuff with args */ }
  
  std::tuple&lt;char,short,int,float,double&gt; data = {1,3,5};
  
  map_call&lt;3, add&gt;(do_stuff, data, 1); //&lt; what I'm trying to do
  // calls do_stuff(add::f&lt;0&gt;(data,2), add::f&lt;1&gt;(data,1),  add::f&lt;2&gt;(data,1) )
  // i.e.  do_stuff(2,4,5)
  </code></pre>
  
  <p>Where one of the (failed try) implementations of <code>map_call</code> is given below:</p>
  
  <pre><code>// what I tried:
  template&lt;class Mapped, class Indicies&gt; struct map_call_help;
  template&lt;class Mapped, int... indices&gt;
  struct map_call_help&lt;Mapped, std::integer_sequence&lt;int, indices...&gt;&gt;
  {
      template&lt;class Callable, class... Args&gt;
      static inline void f(Callable &amp;&amp; call, Args &amp;&amp; ... args)
      {
          call( Mapped::f&lt;indices&gt;(std::forward&lt;Args&gt;(args)...) ...);
          //                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^      1
          //    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 2
          // nested expansion fails with parse error / expected ')'
          // inner expansion is: std::forward&lt;Args&gt;(args)...
          // outer expansion is: Mapped::f&lt;indices&gt;(_forwarded_args_)...
      }
  };
  template&lt;int n, class Mapped, class Callable, class... Args&gt;
  inline void map_call(Callable &amp;&amp; call, Args &amp;&amp; ... args)
  {
      map_call_help&lt;Mapped, std::make_integer_sequence&lt;int, n&gt;&gt;::f(
            std::forward&lt;Callable&gt;(call), std::forward&lt;Args&gt;(args)... );
  }
  </code></pre>
  
  <p><code>integer_sequence</code> related stuff needs <code>#include &lt;utility&gt;</code> and C++14, or it can be implemented in C++11 -- see e.g. answers to <a href="https://stackoverflow.com/questions/7858817/unpacking-a-tuple-to-call-a-matching-function-pointer">this question</a> if interested.</p>