Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>It depends on what you are passing it to, if the template you're trying to instantiate takes as a parameter a class template accepting 2 (or in c++11 a variadic number of) classes then you can pass std::vector to that. In most cases however, templates require classes as parameters and you cannot pass the class template std::vector.</p> <pre><code> template &lt;class T&gt; struct gimme_a_type{}; template &lt;template &lt;class,class&gt; class T&gt; struct gimme_a_template{}; gimme_a_type&lt;std::vector&gt; //&lt;-- does not compile, expected a type, got a template gimme_a_type&lt;std::vector&lt;int&gt; &gt; //&lt;-- compiles, expected a type, got a type gimme_a_template&lt;std::vector&gt; //&lt;-- compiles, expected a template, got a template that has the correct signature gimme_a_template&lt;std::vector&lt;int&gt; &gt; //&lt;-- does not compile, expected a template, got a type </code></pre> <p>In response to your edit, there are difficulties to using class templates as template parameters. Matching the number of parameters exactly is actually difficult to do when you have default arguments in the class template you're trying to pass (<code>std::vector</code> in our case). Notice that the example above required a class template that takes 2 classes, not just one. This is because <code>std::vector</code> takes two parameters, the second is just defaulted to <code>std::allocator&lt;T&gt;</code> for us.</p> <p>The following example demonstrates the issue:</p> <pre><code> template &lt;template &lt;class, class&gt; class Tem&gt; struct A { Tem&lt;int&gt; v; //&lt;-- fails to compile on gcc, Tem takes two parameters Tem&lt;int, std::allocator&lt;int&gt; &gt;; //&lt;-- compiles, but requires a priori knowledge of Tem }; template &lt;template &lt;class...&gt; class Tem&gt; struct A2 { Tem&lt;int&gt; v; //&lt;-- This C++11 example will work, but still isn't perfect. }; </code></pre> <p>The C++11 example is better, but if someone passed a class that has as a signature <code>template &lt;class, bool = false&gt; class A3</code> it fails again because <code>A2</code> requires a variadic number of classes, not a variadic number of whatevers. So even though <code>A3&lt;int&gt;</code> could be a valid instantiation you couldn't pass that class to <code>A2</code>.<br> The solution there is to always use types in template parameter lists and use the <code>std::integral_constant</code> wrapper template to pass integral constants around.</p>
    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.
 

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