Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>N.B. this part of your question is not possible:</p> <pre><code>template&lt;class Packed&gt; struct foo : unpack&lt;Packed&gt;::type...{}; </code></pre> <p><code>Packed</code> is not a parameter pack here, so cannot be used in a pack expansion. If you changed it to:</p> <pre><code>template&lt;class Packed&gt; struct foo&lt;packed&lt;Packed...&gt; : unpack&lt;Packed&gt;::type...{}; </code></pre> <p>then you could expand the parameter pack, but now <code>unpack</code> would only be passed a single type, and would have no way to know which index it was, i.e. what <code>N</code> should be for <code>node&lt;Pn, N&gt;</code></p> <p>To make it work you need to combine the type parameter pack with a non-type parameter pack of integers, which your <code>values</code> gets close to, but you have the indirection of deriving from <code>unpack</code> not a list of <code>node</code> types.</p> <p>I think this is what you're asking for (edited after misunderstanding the <code>node</code> part), using my <a href="https://gitorious.org/redistd/redistd/blobs/master/include/redi/index_tuple.h" rel="nofollow noreferrer"><code>index_tuple</code></a> utility, which could easily be replaced by litb's <a href="https://stackoverflow.com/a/7858971/981959"><code>seq</code></a> template or any similar type. The non-type parameter pack of integers is deduced as a default template argument and can then be used in the base-class list of <code>foo</code>:</p> <pre><code>#include &lt;redi/index_tuple.h&gt; template&lt;typename T, unsigned N&gt; struct node { }; template&lt;typename... T&gt; struct packed { }; template&lt;typename T&gt; struct index_tuple_from_packed; template&lt;typename... T&gt; struct index_tuple_from_packed&lt;packed&lt;T...&gt;&gt; { typedef redi::to_index_tuple&lt;T...&gt; type; }; template&lt;typename T, typename I = typename index_tuple_from_packed&lt;T&gt;::type&gt; struct foo; template&lt;typename... T, unsigned... Indices&gt; struct foo&lt;packed&lt;T...&gt;, redi::index_tuple&lt;Indices...&gt;&gt; : node&lt;T, Indices&gt;... { }; struct A { }; struct B { }; struct C { }; int main() { typedef packed&lt;A, B, C&gt; p; foo&lt;p&gt; d; node&lt;A, 0&gt;* a = &amp;d; node&lt;B, 1&gt;* b = &amp;d; node&lt;C, 2&gt;* c = &amp;d; } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
 

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