title: Print using C++ variadic template
body: <p>I made the task where I have to make print in C# style
  <b><pre>tprintf(&quot;{} world{} {} {} {}\n&quot;,&quot;Hello&quot;,'!',123,&quot; Je&quot;, &quot;end&quot;);</pre></b></p>
  <p>And the code is below</p>
  <pre><code>void tprintf(const char* format) // base function
  {
      std::cout &lt;&lt; format;
  }
  
  template&lt;typename T, typename... Targs&gt;
  void tprintf(const char* format, T value, Targs... Fargs)
  {
      for ( ; *format != '\0'; format++ ) {
             if(*format == '{'){
                  if(format[1] == '}'){
             std::cout &lt;&lt; value;
             tprintf(format+2, Fargs...); // recursive call
             return;
             }
          }
          std::cout &lt;&lt; *format;
      }
  }
  </code></pre>
  <p>Now I have to make something little different:</p>
  <pre>tprintf("{1} {3} + {2} = {4} {1}.", "11", 7.5 , 4, 11.5);</pre>
  <p>output:</p>
  <p><b><pre>11 4 + 7.5 = 11.5 11.</pre></b></p>
  <p>So I think here simple recursion iteration over args doesn't work. I have to know all args which are come to function. I think I should do is at beginning get all args to array and then input them in correct place in pattern string. But how?</p>
  <p>I made this</p>
  <pre><code>template&lt;typename... Args&gt; inline string pass(Args&amp;&amp;...) {return &quot;End&quot;;}
  
  template&lt;typename T&gt;
  string some_function(T a){
      std::ostringstream ostr;
      ostr &lt;&lt; a;
      //cout&lt;&lt;ostr.str();
      return ostr.str();
  }
  
    template&lt;typename... Args&gt; inline void expand(Args&amp;&amp;... args) {
      string a=&quot;&quot;;
          
      a.append(pass( some_function(args)... ))&lt;&lt;endl;
  
      cout&lt;&lt;&quot; result &quot;&lt;&lt;a&lt;&lt;endl;
    }
  
  struct pass {
      template&lt;typename ...T&gt; pass(T...) {}
    };
  </code></pre>
  <p>But this only return &quot;End&quot;. I realize cause of this behavior is connected which template behavior and recursion. The last think which is invoke in recursion is
  template&lt;typename... Args&gt; inline string pass(Args&amp;&amp;...) {return &quot;End&quot;;} so I expand function I get only End string not a string including all args parsed to strings.</p>
  <p>So my question is how make this function work fine</p>
  <pre>tprintf("{1} {3} + {2} = {4} {1}.", "", 7.5 , 4, 11.5);</pre>