title: Variadic template data structures
body: <p>Variadic templates are are templates that receive a varying number of arguments, and can use used with models that can operate with generic types </p>
  <p>Code:</p>
  <pre><code>    #include &lt;iostream&gt;
      
      template &lt;class ...Rest&gt;
      struct Test {};
      
      template &lt;class T, class ...Rest&gt;
      struct Test &lt;T, Rest...&gt; {
          Test(T first, Rest... rest)
            : first(first)
           {}
      
          T first;
      };
      
      template &lt;class T&gt;
      void Print1(T &amp;data)
      {
          std::cout &lt;&lt; data.first &lt;&lt; std::endl;
      }
      
      template &lt;class T, class ...Rest&gt;
      void Print2(Test&lt;T, Rest...&gt; &amp;data)
      {
          std::cout &lt;&lt; data.first &lt;&lt; std::endl;
      }
      
      template &lt;class T&gt;
      struct Helper;
      
      template &lt;class T, class ...Rest&gt;
      struct Helper&lt;Test&lt;T, Rest...&gt;&gt; {
         static void Print(Test&lt;T, Rest...&gt; &amp;data){
             std::cout &lt;&lt; data.first &lt;&lt; std::endl;
         }
      };
      
      int main() {
          Test&lt;int, float, bool&gt; ex(15, 41.59, true);
      
          using type = decltype(ex); //Test&lt;int, float, bool&gt;
        
          Print1(ex);
      
          Print2(ex);
      
          Helper&lt;type&gt;::Print(ex);
        
          std::cout &lt;&lt; &quot;END!&quot; &lt;&lt; std::endl;
          return 0;
      }
  </code></pre>
  <p>Observation: The reason for this question was asked to understand the varidiac template operation, for this reason I am not concerned with the use of the program, in this example above: The Test class is losing access to the generated sub-classes (rest ... )</p>
  <p><em><strong>The question:</strong></em></p>
  <ol>
  <li><strong>First topic of the doubt:</strong> <strong>I understand that functions and classes can have template , but what does &lt;T, Rest ...&gt; mean after the definition &quot;class Test&quot;?</strong>, I already seen template &lt; class T &gt; class Some {}, but never template &lt; class T &gt; class Some &lt; T &gt; {}, See below my understanding of the case:</li>
  </ol>
  <pre><code>template &lt;class T, class ...Rest&gt;
  void Func(T first, Rest ...rest){
      std::cout &lt;&lt; first &lt;&lt; std::endl;
  
      Func(rest...); //1 call is [T=float,Rest=&lt;bool&gt;], and 2 call is [T=bool] (Futures calls)
  }
  //Call: Func (1, 1.55, true), [T equals &quot;int&quot;, Rest equals &lt;float, bool&gt;]
  </code></pre>
  <ol start="2">
  <li><p><strong>Second topic of the doubt:</strong> <strong>In function &quot;Print2&quot;, Why the template that was deduced for Print2 call is &lt;int, float, bool&gt;?</strong> Since the first parameter is the variable &quot;ex&quot;, I don't understand why the result is different from: [T = Test &lt;int, float, bool&gt;] (Print2&lt;Test&lt;int, float, bool&gt;&gt;). Instead, the result obtained was [T = int, Rest = &lt;float, bool&gt;] (Print2&lt;int, float, bool&gt;)</p>
  </li>
  <li><p><strong>Third topic of the doubt:</strong> This topic mentions the 1st topic (where the &lt;&gt; is being defined after the structure) <strong>The template is &lt;class T, class ... Rest&gt;. What does Test&lt;T, Rest...&gt; means after the definition &quot;struct Helper&quot;?</strong> Note that it was used as follows: &quot;<strong>Test</strong> &lt;T, Rest ...&gt;&quot;, instead of &quot;&lt;T, Rest ...&gt;&quot; in first (1st) topic</p>
  </li>
  <li><p><strong>Fourth topic of the doubt:</strong> This topic mentions the 2st topic (where the template was deduced for Print2) <strong>Why was it necessary to pass only Test &lt;int, float, bool&gt; as the type, instead of &lt;int, float, bool&gt;? What I want to know is how this self-deduction (&quot;type&quot; turns into -&gt; [T=int, Rest=&lt;float, bool&gt;]) was made by C++?</strong> Note that in the second topic, where the call to the function Print2, is equivalent to Print2 &lt;int, flooat, bool&gt;. using type = Test&lt;int, float, bool&gt;</p>
  </li>
  </ol>
  <p>Complements of the 4st topic: Helper::Print(ex), <strong>&quot;type&quot; is equivalent</strong> to Test&lt;int, float, bool&gt;, I noticed that &quot;T&quot; became, &quot;int&quot; (the first type), &quot;Rest&quot; became &quot;&lt;float, bool&gt;&quot; (the other types used to build the sutrct Test that is in variable &quot;ex&quot;)</p>
  <p>Thanks in advance.</p>