Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>This can be done fairly easily using a <code>std::tuple</code> to specify your list of types. All we need to do is declare the primary template to take two parameters, then create a partial specialization where those type parameters are tuples. In the partial specialization, we can use the argument deduction to capture the template parameters of the tuple and re-use them for our purposes. We could create a new template for the purposes of specifying the list of types (i.e. <code>Types&lt;int,double&gt;</code>), but a tuple is especially nice in this case because you need to have a way to access the the individual rows anyway, and a <code>std::tuple</code> provides a built-in way to do this through <code>std::get&lt;i&gt;</code>. Using the tuple for the template parameters may make it more obvious that you use <code>std::get</code> to access the rows.</p> <p>Here's a complete example:</p> <pre><code>#include &lt;string&gt; #include &lt;tuple&gt; #include &lt;vector&gt; // primary template template &lt;typename RowTuple,typename RowInfoTuple&gt; struct Rows; // variadic partial specialization template &lt;typename... RowTypes,typename... RowInfoTypes&gt; struct Rows&lt;std::tuple&lt;RowTypes...&gt;,std::tuple&lt;RowInfoTypes...&gt;&gt; { // use variadic expansion to make a tuple of vectors std::tuple&lt;std::vector&lt;RowTypes&gt;...&gt; rows; std::tuple&lt;RowInfoTypes...&gt; rowinfos; }; struct rss_feed { }; int main(int,char**) { Rows&lt; std::tuple&lt;double,int&gt;, std::tuple&lt;std::string,rss_feed&gt; &gt; data; std::get&lt;0&gt;(data.rows).push_back(1.5); std::get&lt;1&gt;(data.rows).push_back(2); std::get&lt;0&gt;(data.rowinfos) = "info"; std::get&lt;1&gt;(data.rowinfos) = rss_feed(); return 0; } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload