Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><code>template&lt;&gt;</code> tells the compiler that a template specialization follows, specifically a <strong>full specialization</strong>. Normally, <code>class A</code> would have to look something like this:</p> <pre><code>template&lt;class T&gt; class A{ // general implementation }; template&lt;&gt; class A&lt;int&gt;{ // special implementation for ints }; </code></pre> <p>Now, whenever <code>A&lt;int&gt;</code> is used, the specialized version is used. You can also use it to specialize functions:</p> <pre><code>template&lt;class T&gt; void foo(T t){ // general } template&lt;&gt; void foo&lt;int&gt;(int i){ // for ints } // doesn't actually need the &lt;int&gt; // as the specialization can be deduced from the parameter type template&lt;&gt; void foo(int i){ // also valid } </code></pre> <p>Normally though, you shouldn't specialize functions, as <a href="http://www.gotw.ca/publications/mill17.htm">simple overloads are generally considered superior</a>:</p> <pre><code>void foo(int i){ // better } </code></pre> <hr> <p>And now, to make it overkill, the following is a <strong>partial specialization</strong>:</p> <pre><code>template&lt;class T1, class T2&gt; class B{ }; template&lt;class T1&gt; class B&lt;T1, int&gt;{ }; </code></pre> <p>Works the same way as a full specialization, just that the specialized version is used whenever the second template parameter is an <code>int</code> (e.g., <code>B&lt;bool,int&gt;</code>, <code>B&lt;YourType,int&gt;</code>, etc).</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