Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You can't. The template template parameter means that you take a template name <strong>without supplied template arguments</strong>.</p> <pre><code>Foo&lt; Param &gt; tt; </code></pre> <p>Here you can see that no values are supplied for <code>Param</code>. You'd take a template template parameter so that Foo itself could instantiate <code>Params</code> with any arguments it likes.</p> <p>Example:</p> <pre><code>template &lt; template &lt; int, int &gt; class X1&gt; struct Foo { X1&lt;1, 2&gt; member; X1&lt;42, 100&gt; foo(); }; template &lt;int N, int P&gt; struct A {}; template &lt;int X, int Y&gt; struct B {}; Foo&lt;A&gt; a_foo; //has a member of type A&lt;1, 2&gt;, foo returns A&lt;42, 100&gt; Foo&lt;B&gt; b_foo; //has a member of type B&lt;1, 2&gt;, foo returns B&lt;42, 100&gt; </code></pre> <hr> <p>But if you want your <code>Foo</code> to output those integers, it has to take real types, not templates. Secondly, the names of the template arguments (<code>X</code> and <code>Y</code>) are only meaningful where they are in scope. They are otherwise completely arbitrary identifiers. You can retrieve the values with simple metaprogramming:</p> <pre><code>#include &lt;cstdio&gt; template &lt;class T&gt; struct GetArguments; //partial specialization to retrieve the int parameters of a T&lt;int, int&gt; template &lt;template &lt;int, int&gt; class T, int A, int B&gt; struct GetArguments&lt;T&lt;A, B&gt; &gt; { enum {a = A, b = B}; }; //this specialization also illustrates another use of template template parameters: //it is used to pick out types that are templates with two int arguments template &lt;class X1&gt; struct Foo { int foo() { printf("ok%d %d\n", GetArguments&lt;X1&gt;::a, GetArguments&lt;X1&gt;::b); return 0; } }; template &lt; int X, int Y &gt; class Param { public: void print(); }; //this is to illustrate X and Y are not essential part of the Param template //in this method definition I have chosen to call them something else template &lt;int First, int Second&gt; void Param&lt;First, Second&gt;::print() { printf("Param&lt;%d, %d&gt;\n", First, Second); } int main() { Foo&lt; Param&lt;10, 20&gt; &gt; tt; tt.foo(); Param&lt;10, 20&gt; p; p.print(); return 0; } </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. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    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