How to iterate over variadic template pack during (pseudo?) runtime?
<p>I want to create somewhat sibling of <code>std::fscanf()</code> (I know it's a C function). So, my interface is something like this:</p>

<pre><code>template &lt;charT, char_traits, ...&gt;
std::size_t ts_scanf(is, format, opening_bracket, closing_bracket, args)
</code></pre>

<p>I decided to implement a C# version of reading from console, since it requires programmer to maintain only one sequence (the args part), not the arguments and format. </p>

<p>Here is how <strong>C# version</strong> works:</p>

<pre><code>"text blah blah blah {0} {1} {0}", arg1, arg2
</code></pre>

<p>So, it infers types of arg1, arg2, and then reads the text in location where {N} stands into the appropriate argument. </p>

<p><strong>Algorithm</strong> of what I want to do:</p>

<p>1.Find opening bracket</p>

<p>2.Try to parse an int, say N</p>

<p>3.if succeeded, get the Nth parameter from the pack, read into it using <code>is&gt;&gt;get&lt;N&gt;args</code>.</p>

<p>4.if failed,perform dumb read </p>

<p>5.Repeat 1 to 4 until the end of the format or until stream exhausts</p>

<p>So, when writing a loop I encountered <strong>a problem</strong>:</p>

<pre><code>for (i = 0; i &lt; length; i = format.find(i, opening_bracket))
</code></pre>

<p>I found that I need to somehow expand the parameter pack <code>args</code>, which is impossible to do at runtime (since the loop is runtime). The only solution I have in mind is recurse: when finding opening bracket, read it, trim the format string, and recurse with the trimmed string and the rest of the variadic pack.</p>

<p><strong>Question:</strong> is there a solution where it would be possible to expand the variadic pack at (pseudo) runtime? </p>