Tuple to parameter pack
<p>This below code from user Faheem Mitha, is based on user Johannes Schaub - litb's answer in this <a href="https://stackoverflow.com/a/9288547/1655492">SO</a>. This code perfectly does what I seek, which is conversion of a <code>tuple</code> into parameter pack, but I don't understand this code well enough and therefore I thought I will create a new discussion that might help template metaprogramming newbies like me. So, please pardon the duplicate posting.</p>

<p>Now moving onto the code</p>

<pre><code>#include &lt;tuple&gt;
#include &lt;iostream&gt;
using std::cout;
using std::endl;

template&lt;int ...&gt; struct seq {};

template&lt;int N, int ...S&gt; struct gens : gens&lt;N - 1, N - 1, S...&gt; { };

template&lt;int ...S&gt; struct gens&lt;0, S...&gt;{ typedef seq&lt;S...&gt; type; };

double foo(int x, float y, double z)
{
    return x + y + z;
}

template &lt;typename ...Args&gt;
struct save_it_for_later
{
    std::tuple&lt;Args...&gt; params;
    double(*func)(Args...);

    double delayed_dispatch()
    {
        return callFunc(typename gens&lt;sizeof...(Args)&gt;::type()); // Item #1
    }

    template&lt;int ...S&gt;
    double callFunc(seq&lt;S...&gt;)
    {
        return func(std::get&lt;S&gt;(params) ...);
    }
};

int main(void)
{
    std::tuple&lt;int, float, double&gt; t = std::make_tuple(1, (float)1.2, 5);
    save_it_for_later&lt;int, float, double&gt; saved = { t, foo };
    cout &lt;&lt; saved.delayed_dispatch() &lt;&lt; endl;
    return 0;
}
</code></pre>

<p>I'm completely confounded by Item #1 above:</p>

<ul>
<li>What purpose does <code>typename</code> serve on that line?</li>
<li>I understand that <code>gens&lt;sizeof...(Args)&gt;::type()</code> will expand to <code>gens&lt;3&gt;::type()</code>, but that doesn't seem to match neither <code>template&lt;int N, int ...S&gt; struct gens : gens&lt;N - 1, N - 1, S...&gt; { };</code> nor <code>template&lt;int ...S&gt; struct gens&lt;0, S...&gt;</code>. I'm obviously missing the point and I'd be glad if someone can explain what is happening here.</li>
</ul>

<p>I do understand that <code>callFunc</code> gets invoked in this form <code>callFunc(seq&lt;0,1,2&gt;)</code> and the return statement of this method itself expands to <code>return func(std::get&lt;0&gt;(params), std::get&lt;1&gt;(params), std::get&lt;2&gt;(params)</code> and this is what makes this scheme work, but I cannot workout how this <code>seq&lt;0,1,2&gt;</code> type is generated.</p>

<p>Note: Using <code>std::index_sequence_for</code> is not an option, my compiler doesn't support C++14 features.</p>

<p>PS: Can this technique be classified as template metaprogramming?</p>