<!DOCTYPE html><html lang='en'><head><title>[temp.class.spec]</title><meta charset='UTF-8'/><link rel='stylesheet' type='text/css' href='14882.css'/><link rel='stylesheet' type='text/css' href='expanded.css' title='Notes and examples expanded'/><link rel='alternate stylesheet' type='text/css' href='colored.css' title='Notes and examples colored'/><link rel='alternate stylesheet' type='text/css' href='collapsed.css' title='Notes and examples collapsed'/><link rel='icon' href='icon.png'/></head><body><div class='wrapper'><h1 ><a class='secnum' style='min-width:73pt'>12</a> Templates <a class='abbr_ref' href='./#temp'>[temp]</a></h1><h2 ><a class='secnum' style='min-width:88pt'>12.6</a> Template declarations <a class='abbr_ref' href='temp.decls#temp.class.spec'>[temp.decls]</a></h2><h3 ><a class='secnum' style='min-width:103pt'>12.6.5</a> Class template partial specializations <a class='abbr_ref'>[temp.class.spec]</a></h3><div class='para' id='1'><div class='marginalizedparent'><a class='marginalized' href='#1'>1</a></div><div class='sourceLinkParent'><a class='sourceLink' href='https://github.com/Eelis/draft73ca144c7e48612fe72742f9f6a5ec9ad6a934d2/source/templates.tex#L2964'>#</a></div><div id='1.sentence-1' class='sentence'><span class='indexparent'><a class='index' id=':specialization,class_template_partial'></a></span>A
<a class='hidden_link' href='#def:template,primary' id='def:template,primary'><i >primary class template</i></a>
declaration is one in which the class template name is an
identifier<a class='hidden_link' href='#1.sentence-1'>.</a></div> <div id='1.sentence-2' class='sentence'>A template declaration in which the class template name is a
<i ><a href='temp.names#nt:simple-template-id'>simple-template-id</a></i>
is a
<a class='hidden_link' href='#def:specialization,class_template_partial' id='def:specialization,class_template_partial'><i >partial specialization</i></a>
of the class template named in the
<i ><a href='temp.names#nt:simple-template-id'>simple-template-id</a></i><a class='hidden_link' href='#1.sentence-2'>.</a></div> <div id='1.sentence-3' class='sentence'>A partial specialization of a class template provides an alternative definition
of the template that is used instead of the primary definition when the
arguments in a specialization match those given in the partial
specialization (<a href='#match'>[temp.class.spec.match]</a>)<a class='hidden_link' href='#1.sentence-3'>.</a></div> <div id='1.sentence-4' class='sentence'>The primary template shall be declared before any specializations of
that template<a class='hidden_link' href='#1.sentence-4'>.</a></div> <div id='1.sentence-5' class='sentence'>A partial specialization shall be declared before the first use of a class template
specialization that would make use of the partial specialization as the result of
an implicit or explicit instantiation in every translation unit in which such a use
occurs; no diagnostic is required<a class='hidden_link' href='#1.sentence-5'>.</a></div></div><div class='para' id='2'><div class='marginalizedparent'><a class='marginalized' href='#2'>2</a></div><div class='sourceLinkParent'><a class='sourceLink' href='https://github.com/Eelis/draft73ca144c7e48612fe72742f9f6a5ec9ad6a934d2/source/templates.tex#L2988'>#</a></div><div id='2.sentence-1' class='sentence'>Each class template partial specialization is a distinct template and
definitions shall be provided for the members of a template partial
specialization (<a href='#mfunc'>[temp.class.spec.mfunc]</a>)<a class='hidden_link' href='#2.sentence-1'>.</a></div></div><div class='para' id='3'><div class='marginalizedparent'><a class='marginalized' href='#3'>3</a></div><div class='sourceLinkParent'><a class='sourceLink' href='https://github.com/Eelis/draft73ca144c7e48612fe72742f9f6a5ec9ad6a934d2/source/templates.tex#L2993'>#</a></div><div id='3.example-1' class='example'>[<span style='white-space:nowrap'> </span><a class='example_link' href='#3.example-1'><span class='textit'>Example</span></a><div class='exampleBody'><span class='textit'>:</span> <pre class='codeblock'>
<span class='keyword'>template</span><span class='anglebracket'>&lt;</span><span class='keyword'>class</span> T1, <span class='keyword'>class</span> T2, <span class='keyword'>int</span> I<span class='anglebracket'>&gt;</span> <span class='keyword'>class</span> A             <span class='curlybracket'>{</span> <span class='curlybracket'>}</span>;
<span class='keyword'>template</span><span class='anglebracket'>&lt;</span><span class='keyword'>class</span> T, <span class='keyword'>int</span> I<span class='anglebracket'>&gt;</span>            <span class='keyword'>class</span> A<span class='anglebracket'>&lt;</span>T, T<span class='operator'>*</span>, I<span class='anglebracket'>&gt;</span>   <span class='curlybracket'>{</span> <span class='curlybracket'>}</span>;
<span class='keyword'>template</span><span class='anglebracket'>&lt;</span><span class='keyword'>class</span> T1, <span class='keyword'>class</span> T2, <span class='keyword'>int</span> I<span class='anglebracket'>&gt;</span> <span class='keyword'>class</span> A<span class='anglebracket'>&lt;</span>T1<span class='operator'>*</span>, T2, I<span class='anglebracket'>&gt;</span> <span class='curlybracket'>{</span> <span class='curlybracket'>}</span>;
<span class='keyword'>template</span><span class='anglebracket'>&lt;</span><span class='keyword'>class</span> T<span class='anglebracket'>&gt;</span>                   <span class='keyword'>class</span> A<span class='anglebracket'>&lt;</span><span class='keyword'>int</span>, T<span class='operator'>*</span>, <span class='literal'>5</span><span class='anglebracket'>&gt;</span> <span class='curlybracket'>{</span> <span class='curlybracket'>}</span>;
<span class='keyword'>template</span><span class='anglebracket'>&lt;</span><span class='keyword'>class</span> T1, <span class='keyword'>class</span> T2, <span class='keyword'>int</span> I<span class='anglebracket'>&gt;</span> <span class='keyword'>class</span> A<span class='anglebracket'>&lt;</span>T1, T2<span class='operator'>*</span>, I<span class='anglebracket'>&gt;</span> <span class='curlybracket'>{</span> <span class='curlybracket'>}</span>;
</pre><div id='3.sentence-1' class='sentence'>The first declaration declares the primary (unspecialized) class template<a class='hidden_link' href='#3.sentence-1'>.</a></div> <div id='3.sentence-2' class='sentence'>The second and subsequent declarations declare partial specializations of
the primary template<a class='hidden_link' href='#3.sentence-2'>.</a></div> —<span style='white-space:nowrap'> </span><i>end example</i></div><span style='white-space:nowrap'> </span>]</div> </div><div class='para' id='4'><div class='marginalizedparent'><a class='marginalized' href='#4'>4</a></div><div class='sourceLinkParent'><a class='sourceLink' href='https://github.com/Eelis/draft73ca144c7e48612fe72742f9f6a5ec9ad6a934d2/source/templates.tex#L3008'>#</a></div><div id='4.sentence-1' class='sentence'>A class template partial specialization may be constrained (<a href='temp'>[temp]</a>)<a class='hidden_link' href='#4.sentence-1'>.</a></div> <div id='4.example-1' class='example'>[<span style='white-space:nowrap'> </span><a class='example_link' href='#4.example-1'><span class='textit'>Example</span></a><div class='exampleBody'><span class='textit'>:</span> <pre class='codeblock'>
<span class='keyword'>template</span><span class='anglebracket'>&lt;</span><span class='keyword'>typename</span> T<span class='anglebracket'>&gt;</span> <span class='keyword'>concept</span> C <span class='operator'>=</span> <span class='literal'>true</span>;

<span class='keyword'>template</span><span class='anglebracket'>&lt;</span><span class='keyword'>typename</span> T<span class='anglebracket'>&gt;</span> <span class='keyword'>struct</span> X <span class='curlybracket'>{</span> <span class='curlybracket'>}</span>;
<span class='keyword'>template</span><span class='anglebracket'>&lt;</span><span class='keyword'>typename</span> T<span class='anglebracket'>&gt;</span> <span class='keyword'>struct</span> X<span class='anglebracket'>&lt;</span>T<span class='operator'>*</span><span class='anglebracket'>&gt;</span> <span class='curlybracket'>{</span> <span class='curlybracket'>}</span>;          <span class='comment'>// #1</span>
<span class='keyword'>template</span><span class='anglebracket'>&lt;</span>C T<span class='anglebracket'>&gt;</span> <span class='keyword'>struct</span> X<span class='anglebracket'>&lt;</span>T<span class='anglebracket'>&gt;</span> <span class='curlybracket'>{</span> <span class='curlybracket'>}</span>;                  <span class='comment'>// #2</span>
</pre> <div id='4.sentence-2' class='sentence'>
Both partial specializations are more specialized than the primary template<a class='hidden_link' href='#4.sentence-2'>.</a></div> <div id='4.sentence-3' class='sentence'>#1 is more specialized because the deduction of its template arguments
from the template argument list of the class template specialization succeeds,
while the reverse does not<a class='hidden_link' href='#4.sentence-3'>.</a></div> <div id='4.sentence-4' class='sentence'>#2 is more specialized because the template arguments are equivalent,
but the partial specialization is more constrained (<a href='temp.constr.order'>[temp.constr.order]</a>)<a class='hidden_link' href='#4.sentence-4'>.</a></div> —<span style='white-space:nowrap'> </span><i>end example</i></div><span style='white-space:nowrap'> </span>]</div> </div><div class='para' id='5'><div class='marginalizedparent'><a class='marginalized' href='#5'>5</a></div><div class='sourceLinkParent'><a class='sourceLink' href='https://github.com/Eelis/draft73ca144c7e48612fe72742f9f6a5ec9ad6a934d2/source/templates.tex#L3026'>#</a></div><div id='5.sentence-1' class='sentence'>The template parameters are specified in the angle bracket enclosed list
that immediately follows the keyword
<span class='texttt'>template</span><a class='hidden_link' href='#5.sentence-1'>.</a></div> <div id='5.sentence-2' class='sentence'>For partial specializations, the template argument list is explicitly
written immediately following the class template name<a class='hidden_link' href='#5.sentence-2'>.</a></div> <div id='5.sentence-3' class='sentence'>For primary templates, this list is implicitly described by the
template parameter list<a class='hidden_link' href='#5.sentence-3'>.</a></div> <div id='5.sentence-4' class='sentence'>Specifically, the order of the template arguments is the sequence in
which they appear in the template parameter list<a class='hidden_link' href='#5.sentence-4'>.</a></div> <div id='5.example-1' class='example'>[<span style='white-space:nowrap'> </span><a class='example_link' href='#5.example-1'><span class='textit'>Example</span></a><div class='exampleBody'><span class='textit'>:</span> <div id='5.sentence-5' class='sentence'>The template argument list for the primary template in the example
above is
<span class='texttt'><span class='anglebracket'>&lt;</span>T1,</span>
<span class='texttt'>T2,</span>
<span class='texttt'>I<span class='anglebracket'>&gt;</span></span><a class='hidden_link' href='#5.sentence-5'>.</a></div> —<span style='white-space:nowrap'> </span><i>end example</i></div><span style='white-space:nowrap'> </span>]</div>  <div id='5.note-1' class='note'>[<span style='white-space:nowrap'> </span><a class='note_link' href='#5.note-1'><span class='textit'>Note</span></a><div class='noteBody'><span class='textit'>:</span> <div id='5.sentence-6' class='sentence'>The template argument list shall not be specified in the primary template
declaration<a class='hidden_link' href='#5.sentence-6'>.</a></div> <div id='5.sentence-7' class='sentence'>For example,</div><pre class='codeblock'>
<span class='keyword'>template</span><span class='anglebracket'>&lt;</span><span class='keyword'>class</span> T1, <span class='keyword'>class</span> T2, <span class='keyword'>int</span> I<span class='anglebracket'>&gt;</span>
<span class='keyword'>class</span> A<span class='anglebracket'>&lt;</span>T1, T2, I<span class='anglebracket'>&gt;</span> <span class='curlybracket'>{</span> <span class='curlybracket'>}</span>;                         <span class='comment'>// error</span>
</pre> —<span style='white-space:nowrap'> </span><i>end note</i></div><span style='white-space:nowrap'> </span>]</div> </div><div class='para' id='6'><div class='marginalizedparent'><a class='marginalized' href='#6'>6</a></div><div class='sourceLinkParent'><a class='sourceLink' href='https://github.com/Eelis/draft73ca144c7e48612fe72742f9f6a5ec9ad6a934d2/source/templates.tex#L3054'>#</a></div><div id='6.sentence-1' class='sentence'>A class template partial specialization may be declared in any
scope in which the corresponding primary template
may be defined (<a href='namespace.memdef'>[namespace.memdef]</a>, <a href='class.mem'>[class.mem]</a>, <a href='temp.mem'>[temp.mem]</a>)<a class='hidden_link' href='#6.sentence-1'>.</a></div> <div id='6.example-1' class='example'>[<span style='white-space:nowrap'> </span><a class='example_link' href='#6.example-1'><span class='textit'>Example</span></a><div class='exampleBody'><span class='textit'>:</span> <pre class='codeblock'>
<span class='keyword'>template</span><span class='anglebracket'>&lt;</span><span class='keyword'>class</span> T<span class='anglebracket'>&gt;</span> <span class='keyword'>struct</span> A <span class='curlybracket'>{</span>
  <span class='keyword'>struct</span> C <span class='curlybracket'>{</span>
    <span class='keyword'>template</span><span class='anglebracket'>&lt;</span><span class='keyword'>class</span> T2<span class='anglebracket'>&gt;</span> <span class='keyword'>struct</span> B <span class='curlybracket'>{</span> <span class='curlybracket'>}</span>;
    <span class='keyword'>template</span><span class='anglebracket'>&lt;</span><span class='keyword'>class</span> T2<span class='anglebracket'>&gt;</span> <span class='keyword'>struct</span> B<span class='anglebracket'>&lt;</span>T2<span class='operator'>*</span><span class='operator'>*</span><span class='anglebracket'>&gt;</span> <span class='curlybracket'>{</span> <span class='curlybracket'>}</span>;      <span class='comment'>// partial specialization #1</span>
  <span class='curlybracket'>}</span>;
<span class='curlybracket'>}</span>;

<span class='comment'>// partial specialization of <span class='tcode_in_codeblock'>A&lt;T&gt;&#x200b;::&#x200b;C&#x200b;::&#x200b;B&lt;T2&gt;</span></span>
<span class='keyword'>template</span><span class='anglebracket'>&lt;</span><span class='keyword'>class</span> T<span class='anglebracket'>&gt;</span> <span class='keyword'>template</span><span class='anglebracket'>&lt;</span><span class='keyword'>class</span> T2<span class='anglebracket'>&gt;</span>
  <span class='keyword'>struct</span> A<span class='anglebracket'>&lt;</span>T<span class='anglebracket'>&gt;</span><span class='operator'>:</span><span class='operator'>:</span>C<span class='operator'>:</span><span class='operator'>:</span>B<span class='anglebracket'>&lt;</span>T2<span class='operator'>*</span><span class='anglebracket'>&gt;</span> <span class='curlybracket'>{</span> <span class='curlybracket'>}</span>;                   <span class='comment'>// #2</span>

A<span class='anglebracket'>&lt;</span><span class='keyword'>short</span><span class='anglebracket'>&gt;</span><span class='operator'>:</span><span class='operator'>:</span>C<span class='operator'>:</span><span class='operator'>:</span>B<span class='anglebracket'>&lt;</span><span class='keyword'>int</span><span class='operator'>*</span><span class='anglebracket'>&gt;</span> absip;                     <span class='comment'>// uses partial specialization #2</span>
</pre> —<span style='white-space:nowrap'> </span><i>end example</i></div><span style='white-space:nowrap'> </span>]</div> </div><div class='para' id='7'><div class='marginalizedparent'><a class='marginalized' href='#7'>7</a></div><div class='sourceLinkParent'><a class='sourceLink' href='https://github.com/Eelis/draft73ca144c7e48612fe72742f9f6a5ec9ad6a934d2/source/templates.tex#L3076'>#</a></div><div id='7.sentence-1' class='sentence'>Partial specialization declarations themselves are not found by name lookup<a class='hidden_link' href='#7.sentence-1'>.</a></div> <div id='7.sentence-2' class='sentence'>Rather, when the primary template name is used, any previously-declared partial
specializations of the primary template are also considered<a class='hidden_link' href='#7.sentence-2'>.</a></div> <div id='7.sentence-3' class='sentence'>One consequence is
that a
<i ><a href='namespace.udecl#nt:using-declaration'>using-declaration</a></i>
which refers to a class template does not restrict the set of partial specializations
which may be found through the
<i ><a href='namespace.udecl#nt:using-declaration'>using-declaration</a></i><a class='hidden_link' href='#7.sentence-3'>.</a></div> <div id='7.example-1' class='example'>[<span style='white-space:nowrap'> </span><a class='example_link' href='#7.example-1'><span class='textit'>Example</span></a><div class='exampleBody'><span class='textit'>:</span> <pre class='codeblock'>
<span class='keyword'>namespace</span> N <span class='curlybracket'>{</span>
  <span class='keyword'>template</span><span class='anglebracket'>&lt;</span><span class='keyword'>class</span> T1, <span class='keyword'>class</span> T2<span class='anglebracket'>&gt;</span> <span class='keyword'>class</span> A <span class='curlybracket'>{</span> <span class='curlybracket'>}</span>;     <span class='comment'>// primary template</span>
<span class='curlybracket'>}</span>

<span class='keyword'>using</span> N<span class='operator'>:</span><span class='operator'>:</span>A;                                     <span class='comment'>// refers to the primary template</span>

<span class='keyword'>namespace</span> N <span class='curlybracket'>{</span>
  <span class='keyword'>template</span><span class='anglebracket'>&lt;</span><span class='keyword'>class</span> T<span class='anglebracket'>&gt;</span> <span class='keyword'>class</span> A<span class='anglebracket'>&lt;</span>T, T<span class='operator'>*</span><span class='anglebracket'>&gt;</span> <span class='curlybracket'>{</span> <span class='curlybracket'>}</span>;         <span class='comment'>// partial specialization</span>
<span class='curlybracket'>}</span>

A<span class='anglebracket'>&lt;</span><span class='keyword'>int</span>,<span class='keyword'>int</span><span class='operator'>*</span><span class='anglebracket'>&gt;</span> a;      <span class='comment'>// uses the partial specialization, which is found through the using-declaration</span>
                    <span class='comment'>// which refers to the primary template</span>
</pre> —<span style='white-space:nowrap'> </span><i>end example</i></div><span style='white-space:nowrap'> </span>]</div> </div><div class='para' id='8'><div class='marginalizedparent'><a class='marginalized' href='#8'>8</a></div><div class='sourceLinkParent'><a class='sourceLink' href='https://github.com/Eelis/draft73ca144c7e48612fe72742f9f6a5ec9ad6a934d2/source/templates.tex#L3104'>#</a></div><div id='8.sentence-1' class='sentence'>A non-type argument is non-specialized if it is the name of a non-type
parameter<a class='hidden_link' href='#8.sentence-1'>.</a></div> <div id='8.sentence-2' class='sentence'>All other non-type arguments are specialized<a class='hidden_link' href='#8.sentence-2'>.</a></div></div><div class='para' id='9'><div class='marginalizedparent'><a class='marginalized' href='#9'>9</a></div><div class='sourceLinkParent'><a class='sourceLink' href='https://github.com/Eelis/draft73ca144c7e48612fe72742f9f6a5ec9ad6a934d2/source/templates.tex#L3109'>#</a></div><div id='9.sentence-1' class='sentence'>Within the argument list of a class template partial specialization,
the following restrictions apply:</div><div id='9.sentence-2' class='sentence'><ul class='itemize'><li id='9.1'><div class='marginalizedparent' style='left:-7em'><a class='marginalized' href='#9.1'>(9.1)</a></div><div id='9.1.sentence-1' class='sentence'>The type of a template parameter corresponding to a specialized non-type argument
shall not be dependent on a parameter of the specialization<a class='hidden_link' href='#9.1.sentence-1'>.</a></div> <div id='9.1.example-1' class='example'>[<span style='white-space:nowrap'> </span><a class='example_link' href='#9.1.example-1'><span class='textit'>Example</span></a><div class='exampleBody'><span class='textit'>:</span> <pre class='codeblock'>
<span class='keyword'>template</span> <span class='anglebracket'>&lt;</span><span class='keyword'>class</span> T, T t<span class='anglebracket'>&gt;</span> <span class='keyword'>struct</span> C <span class='curlybracket'>{</span><span class='curlybracket'>}</span>;
<span class='keyword'>template</span> <span class='anglebracket'>&lt;</span><span class='keyword'>class</span> T<span class='anglebracket'>&gt;</span> <span class='keyword'>struct</span> C<span class='anglebracket'>&lt;</span>T, <span class='literal'>1</span><span class='anglebracket'>&gt;</span>;              <span class='comment'>// error</span>

<span class='keyword'>template</span><span class='anglebracket'>&lt;</span> <span class='keyword'>int</span> X, <span class='keyword'>int</span> <span class='parenthesis'>(</span><span class='operator'>*</span>array_ptr<span class='parenthesis'>)</span><span class='squarebracket'>[</span>X<span class='squarebracket'>]</span> <span class='anglebracket'>&gt;</span> <span class='keyword'>class</span> A <span class='curlybracket'>{</span><span class='curlybracket'>}</span>;
<span class='keyword'>int</span> array<span class='squarebracket'>[</span><span class='literal'>5</span><span class='squarebracket'>]</span>;
<span class='keyword'>template</span><span class='anglebracket'>&lt;</span> <span class='keyword'>int</span> X <span class='anglebracket'>&gt;</span> <span class='keyword'>class</span> A<span class='anglebracket'>&lt;</span>X,<span class='operator'>&amp;</span>array<span class='anglebracket'>&gt;</span> <span class='curlybracket'>{</span> <span class='curlybracket'>}</span>;        <span class='comment'>// error</span>
</pre> —<span style='white-space:nowrap'> </span><i>end example</i></div><span style='white-space:nowrap'> </span>]</div> </li><li id='9.2'><div class='marginalizedparent' style='left:-7em'><a class='marginalized' href='#9.2'>(9.2)</a></div><div id='9.2.sentence-1' class='sentence'>The specialization shall be <a href='#def:more_specialized'>more specialized</a>
than the primary template<a class='hidden_link' href='#9.2.sentence-1'>.</a></div></li><li id='9.3'><div class='marginalizedparent' style='left:-7em'><a class='marginalized' href='#9.3'>(9.3)</a></div><div id='9.3.sentence-1' class='sentence'>The template parameter list of a specialization shall not contain default
template argument values<a class='hidden_link' href='#9.3.sentence-1'>.</a><a class='footnotenum' href='#footnote-136'>136</a></div></li><li id='9.4'><div class='marginalizedparent' style='left:-7em'><a class='marginalized' href='#9.4'>(9.4)</a></div><div id='9.4.sentence-1' class='sentence'>An argument shall not contain an unexpanded pack<a class='hidden_link' href='#9.4.sentence-1'>.</a></div> <div id='9.4.sentence-2' class='sentence'>If
an argument is a pack expansion (<a href='temp.variadic'>[temp.variadic]</a>), it shall be
the last argument in the template argument list<a class='hidden_link' href='#9.4.sentence-2'>.</a></div></li></ul></div></div><div class='para' id='10'><div class='marginalizedparent'><a class='marginalized' href='#10'>10</a></div><div class='sourceLinkParent'><a class='sourceLink' href='https://github.com/Eelis/draft73ca144c7e48612fe72742f9f6a5ec9ad6a934d2/source/templates.tex#L3142'>#</a></div><div id='10.sentence-1' class='sentence'>The usual access checking rules do not apply to non-dependent names
used to specify template arguments of the <i ><a href='temp.names#nt:simple-template-id'>simple-template-id</a></i>
of the partial specialization<a class='hidden_link' href='#10.sentence-1'>.</a></div> <div id='10.note-1' class='note'>[<span style='white-space:nowrap'> </span><a class='note_link' href='#10.note-1'><span class='textit'>Note</span></a><div class='noteBody'><span class='textit'>:</span> <div id='10.sentence-2' class='sentence'>The template arguments may be private types or
objects that would normally not be accessible<a class='hidden_link' href='#10.sentence-2'>.</a></div> <div id='10.sentence-3' class='sentence'>Dependent names cannot be checked when declaring the partial specialization,
but will be checked when substituting into the partial specialization<a class='hidden_link' href='#10.sentence-3'>.</a></div> —<span style='white-space:nowrap'> </span><i>end note</i></div><span style='white-space:nowrap'> </span>]</div> </div><div class='footnote' id='footnote-136'><div class='footnoteNumberParent'><a class='marginalized' href='#footnote-136'>136)</a></div><div id='footnote-136.sentence-1' class='sentence'>There is no way in which they could be used<a class='hidden_link' href='#footnote-136.sentence-1'>.</a></div></div><div id='match' class='section'><h4 ><a class='secnum' href='#match' style='min-width:118pt'>12.6.5.1</a> Matching of class template partial specializations <a class='abbr_ref' href='temp.class.spec.match'>[temp.class.spec.match]</a></h4><div class='para' id='match-1'><div class='marginalizedparent'><a class='marginalized' href='#match-1'>1</a></div><div class='sourceLinkParent'><a class='sourceLink' href='https://github.com/Eelis/draft73ca144c7e48612fe72742f9f6a5ec9ad6a934d2/source/templates.tex#L3155'>#</a></div><div id='match-1.sentence-1' class='sentence'>When a class template is used in a context that requires an instantiation of
the class,
it is necessary to determine whether the instantiation is to be generated
using the primary template or one of the partial specializations<a class='hidden_link' href='#match-1.sentence-1'>.</a></div> <div id='match-1.sentence-2' class='sentence'>This is done by matching the template arguments of the class template
specialization with the template argument lists of the partial
specializations<a class='hidden_link' href='#match-1.sentence-2'>.</a></div><div id='match-1.sentence-3' class='sentence'><ul class='itemize'><li id='match-1.1'><div class='marginalizedparent' style='left:-7em'><a class='marginalized' href='#match-1.1'>(1.1)</a></div><div id='match-1.1.sentence-1' class='sentence'>If exactly one matching specialization is found, the instantiation is
generated from that specialization<a class='hidden_link' href='#match-1.1.sentence-1'>.</a></div></li><li id='match-1.2'><div class='marginalizedparent' style='left:-7em'><a class='marginalized' href='#match-1.2'>(1.2)</a></div><div id='match-1.2.sentence-1' class='sentence'>If more than one matching specialization is found,
the <a href='#temp.class.order'>partial order rules</a> are used to determine
whether one of the specializations is more specialized than the
others<a class='hidden_link' href='#match-1.2.sentence-1'>.</a></div> <div id='match-1.2.sentence-2' class='sentence'>If none of the specializations is more specialized than all of the
other matching specializations, then the use of the class template
is ambiguous and the program is ill-formed<a class='hidden_link' href='#match-1.2.sentence-2'>.</a></div></li><li id='match-1.3'><div class='marginalizedparent' style='left:-7em'><a class='marginalized' href='#match-1.3'>(1.3)</a></div><div id='match-1.3.sentence-1' class='sentence'>If no matches are found, the instantiation is generated from the
primary template<a class='hidden_link' href='#match-1.3.sentence-1'>.</a></div></li></ul></div></div><div class='para' id='match-2'><div class='marginalizedparent'><a class='marginalized' href='#match-2'>2</a></div><div class='sourceLinkParent'><a class='sourceLink' href='https://github.com/Eelis/draft73ca144c7e48612fe72742f9f6a5ec9ad6a934d2/source/templates.tex#L3181'>#</a></div><div id='match-2.sentence-1' class='sentence'>A partial specialization matches a given actual template argument
list if the template arguments of the partial specialization can be
<a href='temp.deduct'>deduced</a> from the actual template argument list,
and the deduced template arguments satisfy the <a href='temp.constr.decl#def:associated_constraints'>associated constraints</a>
of the partial specialization, if any<a class='hidden_link' href='#match-2.sentence-1'>.</a></div> <div id='match-2.example-1' class='example'>[<span style='white-space:nowrap'> </span><a class='example_link' href='#match-2.example-1'><span class='textit'>Example</span></a><div class='exampleBody'><span class='textit'>:</span> <pre class='codeblock'>
<span class='keyword'>template</span><span class='anglebracket'>&lt;</span><span class='keyword'>class</span> T1, <span class='keyword'>class</span> T2, <span class='keyword'>int</span> I<span class='anglebracket'>&gt;</span> <span class='keyword'>class</span> A             <span class='curlybracket'>{</span> <span class='curlybracket'>}</span>;    <span class='comment'>// #1</span>
<span class='keyword'>template</span><span class='anglebracket'>&lt;</span><span class='keyword'>class</span> T, <span class='keyword'>int</span> I<span class='anglebracket'>&gt;</span>            <span class='keyword'>class</span> A<span class='anglebracket'>&lt;</span>T, T<span class='operator'>*</span>, I<span class='anglebracket'>&gt;</span>   <span class='curlybracket'>{</span> <span class='curlybracket'>}</span>;    <span class='comment'>// #2</span>
<span class='keyword'>template</span><span class='anglebracket'>&lt;</span><span class='keyword'>class</span> T1, <span class='keyword'>class</span> T2, <span class='keyword'>int</span> I<span class='anglebracket'>&gt;</span> <span class='keyword'>class</span> A<span class='anglebracket'>&lt;</span>T1<span class='operator'>*</span>, T2, I<span class='anglebracket'>&gt;</span> <span class='curlybracket'>{</span> <span class='curlybracket'>}</span>;    <span class='comment'>// #3</span>
<span class='keyword'>template</span><span class='anglebracket'>&lt;</span><span class='keyword'>class</span> T<span class='anglebracket'>&gt;</span>                   <span class='keyword'>class</span> A<span class='anglebracket'>&lt;</span><span class='keyword'>int</span>, T<span class='operator'>*</span>, <span class='literal'>5</span><span class='anglebracket'>&gt;</span> <span class='curlybracket'>{</span> <span class='curlybracket'>}</span>;    <span class='comment'>// #4</span>
<span class='keyword'>template</span><span class='anglebracket'>&lt;</span><span class='keyword'>class</span> T1, <span class='keyword'>class</span> T2, <span class='keyword'>int</span> I<span class='anglebracket'>&gt;</span> <span class='keyword'>class</span> A<span class='anglebracket'>&lt;</span>T1, T2<span class='operator'>*</span>, I<span class='anglebracket'>&gt;</span> <span class='curlybracket'>{</span> <span class='curlybracket'>}</span>;    <span class='comment'>// #5</span>

A<span class='anglebracket'>&lt;</span><span class='keyword'>int</span>, <span class='keyword'>int</span>, <span class='literal'>1</span><span class='anglebracket'>&gt;</span>   a1;                    <span class='comment'>// uses #1</span>
A<span class='anglebracket'>&lt;</span><span class='keyword'>int</span>, <span class='keyword'>int</span><span class='operator'>*</span>, <span class='literal'>1</span><span class='anglebracket'>&gt;</span>  a2;                    <span class='comment'>// uses #2, <span class='tcode_in_codeblock'>T</span> is <span class='tcode_in_codeblock'>int</span>, <span class='tcode_in_codeblock'>I</span> is <span class='tcode_in_codeblock'>1</span></span>
A<span class='anglebracket'>&lt;</span><span class='keyword'>int</span>, <span class='keyword'>char</span><span class='operator'>*</span>, <span class='literal'>5</span><span class='anglebracket'>&gt;</span> a3;                    <span class='comment'>// uses #4, <span class='tcode_in_codeblock'>T</span> is <span class='tcode_in_codeblock'>char</span></span>
A<span class='anglebracket'>&lt;</span><span class='keyword'>int</span>, <span class='keyword'>char</span><span class='operator'>*</span>, <span class='literal'>1</span><span class='anglebracket'>&gt;</span> a4;                    <span class='comment'>// uses #5, <span class='tcode_in_codeblock'>T1</span> is <span class='tcode_in_codeblock'>int</span>, <span class='tcode_in_codeblock'>T2</span> is <span class='tcode_in_codeblock'>char</span>, <span class='tcode_in_codeblock'>I</span> is <span class='tcode_in_codeblock'>1</span></span>
A<span class='anglebracket'>&lt;</span><span class='keyword'>int</span><span class='operator'>*</span>, <span class='keyword'>int</span><span class='operator'>*</span>, <span class='literal'>2</span><span class='anglebracket'>&gt;</span> a5;                    <span class='comment'>// ambiguous: matches #3 and #5</span>
</pre> —<span style='white-space:nowrap'> </span><i>end example</i></div><span style='white-space:nowrap'> </span>]</div>  <div id='match-2.example-2' class='example'>[<span style='white-space:nowrap'> </span><a class='example_link' href='#match-2.example-2'><span class='textit'>Example</span></a><div class='exampleBody'><span class='textit'>:</span> <pre class='codeblock'>
<span class='keyword'>template</span><span class='anglebracket'>&lt;</span><span class='keyword'>typename</span> T<span class='anglebracket'>&gt;</span> <span class='keyword'>concept</span> C <span class='operator'>=</span> <span class='keyword'>requires</span> <span class='parenthesis'>(</span>T t<span class='parenthesis'>)</span> <span class='curlybracket'>{</span> t<span class='operator'>.</span>f<span class='parenthesis'>(</span><span class='parenthesis'>)</span>; <span class='curlybracket'>}</span>;

<span class='keyword'>template</span><span class='anglebracket'>&lt;</span><span class='keyword'>typename</span> T<span class='anglebracket'>&gt;</span> <span class='keyword'>struct</span> S <span class='curlybracket'>{</span> <span class='curlybracket'>}</span>;      <span class='comment'>// #1</span>
<span class='keyword'>template</span><span class='anglebracket'>&lt;</span>C T<span class='anglebracket'>&gt;</span> <span class='keyword'>struct</span> S<span class='anglebracket'>&lt;</span>T<span class='anglebracket'>&gt;</span> <span class='curlybracket'>{</span> <span class='curlybracket'>}</span>;          <span class='comment'>// #2</span>

<span class='keyword'>struct</span> Arg <span class='curlybracket'>{</span> <span class='keyword'>void</span> f<span class='parenthesis'>(</span><span class='parenthesis'>)</span>; <span class='curlybracket'>}</span>;

S<span class='anglebracket'>&lt;</span><span class='keyword'>int</span><span class='anglebracket'>&gt;</span> s1;                              <span class='comment'>// uses #1; the constraints of #2 are not satisfied</span>
S<span class='anglebracket'>&lt;</span>Arg<span class='anglebracket'>&gt;</span> s2;                              <span class='comment'>// uses #2; both constraints are satisfied but #2 is more specialized</span>
</pre> —<span style='white-space:nowrap'> </span><i>end example</i></div><span style='white-space:nowrap'> </span>]</div> </div><div class='para' id='match-3'><div class='marginalizedparent'><a class='marginalized' href='#match-3'>3</a></div><div class='sourceLinkParent'><a class='sourceLink' href='https://github.com/Eelis/draft73ca144c7e48612fe72742f9f6a5ec9ad6a934d2/source/templates.tex#L3216'>#</a></div><div id='match-3.sentence-1' class='sentence'>If the template arguments of a partial specialization cannot be deduced
because of the structure of its <i ><a href='temp#nt:template-parameter-list'>template-parameter-list</a></i>
and the <i ><a href='temp.names#nt:template-id'>template-id</a></i>,
the program is ill-formed<a class='hidden_link' href='#match-3.sentence-1'>.</a></div> <div id='match-3.example-1' class='example'>[<span style='white-space:nowrap'> </span><a class='example_link' href='#match-3.example-1'><span class='textit'>Example</span></a><div class='exampleBody'><span class='textit'>:</span> <pre class='codeblock'>
<span class='keyword'>template</span> <span class='anglebracket'>&lt;</span><span class='keyword'>int</span> I, <span class='keyword'>int</span> J<span class='anglebracket'>&gt;</span> <span class='keyword'>struct</span> A <span class='curlybracket'>{</span><span class='curlybracket'>}</span>;
<span class='keyword'>template</span> <span class='anglebracket'>&lt;</span><span class='keyword'>int</span> I<span class='anglebracket'>&gt;</span> <span class='keyword'>struct</span> A<span class='anglebracket'>&lt;</span>I<span class='operator'>+</span><span class='literal'>5</span>, I<span class='operator'>*</span><span class='literal'>2</span><span class='anglebracket'>&gt;</span> <span class='curlybracket'>{</span><span class='curlybracket'>}</span>;     <span class='comment'>// error</span>

<span class='keyword'>template</span> <span class='anglebracket'>&lt;</span><span class='keyword'>int</span> I<span class='anglebracket'>&gt;</span> <span class='keyword'>struct</span> A<span class='anglebracket'>&lt;</span>I, I<span class='anglebracket'>&gt;</span> <span class='curlybracket'>{</span><span class='curlybracket'>}</span>;         <span class='comment'>// OK</span>

<span class='keyword'>template</span> <span class='anglebracket'>&lt;</span><span class='keyword'>int</span> I, <span class='keyword'>int</span> J, <span class='keyword'>int</span> K<span class='anglebracket'>&gt;</span> <span class='keyword'>struct</span> B <span class='curlybracket'>{</span><span class='curlybracket'>}</span>;
<span class='keyword'>template</span> <span class='anglebracket'>&lt;</span><span class='keyword'>int</span> I<span class='anglebracket'>&gt;</span> <span class='keyword'>struct</span> B<span class='anglebracket'>&lt;</span>I, I<span class='operator'>*</span><span class='literal'>2</span>, <span class='literal'>2</span><span class='anglebracket'>&gt;</span> <span class='curlybracket'>{</span><span class='curlybracket'>}</span>;    <span class='comment'>// OK</span>
</pre> —<span style='white-space:nowrap'> </span><i>end example</i></div><span style='white-space:nowrap'> </span>]</div> </div><div class='para' id='match-4'><div class='marginalizedparent'><a class='marginalized' href='#match-4'>4</a></div><div class='sourceLinkParent'><a class='sourceLink' href='https://github.com/Eelis/draft73ca144c7e48612fe72742f9f6a5ec9ad6a934d2/source/templates.tex#L3233'>#</a></div><div id='match-4.sentence-1' class='sentence'>In a type name that refers to a class template specialization, (e.g.,
<span class='texttt'>A<span class='anglebracket'>&lt;</span><span class='keyword'>int</span>, <span class='keyword'>int</span>, <span class='literal'>1</span><span class='anglebracket'>&gt;</span></span>)
the argument list shall match the template parameter list of the primary
template<a class='hidden_link' href='#match-4.sentence-1'>.</a></div> <div id='match-4.sentence-2' class='sentence'>The template arguments of a specialization are deduced from the arguments
of the primary template<a class='hidden_link' href='#match-4.sentence-2'>.</a></div></div></div><div id='temp.class.order' class='section'><h4 ><a class='secnum' href='#temp.class.order' style='min-width:118pt'>12.6.5.2</a> Partial ordering of class template specializations <a class='abbr_ref' href='temp.class.order'>[temp.class.order]</a></h4><div class='para' id='temp.class.order-1'><div class='marginalizedparent'><a class='marginalized' href='#temp.class.order-1'>1</a></div><div class='sourceLinkParent'><a class='sourceLink' href='https://github.com/Eelis/draft73ca144c7e48612fe72742f9f6a5ec9ad6a934d2/source/templates.tex#L3243'>#</a></div><div id='temp.class.order-1.sentence-1' class='sentence'>For two class template partial specializations,
the first is <a class='hidden_link' href='#def:more_specialized,class_template' id='def:more_specialized,class_template'><i >more specialized</i></a> than the second if, given the following
rewrite to two function templates, the first function template is more
specialized than the second according to the <a href='temp.func.order'>ordering rules for function
templates</a>:</div><div id='temp.class.order-1.sentence-2' class='sentence'><ul class='itemize'><li id='temp.class.order-1.1'><div class='marginalizedparent' style='left:-7em'><a class='marginalized' href='#temp.class.order-1.1'>(1.1)</a></div><div id='temp.class.order-1.1.sentence-1' class='sentence'>Each of the two
function templates has the same template parameters
and <a href='temp.constr.decl#def:associated_constraints'>associated constraints</a>
as the corresponding partial specialization<a class='hidden_link' href='#temp.class.order-1.1.sentence-1'>.</a></div></li><li id='temp.class.order-1.2'><div class='marginalizedparent' style='left:-7em'><a class='marginalized' href='#temp.class.order-1.2'>(1.2)</a></div><div id='temp.class.order-1.2.sentence-1' class='sentence'>Each function template
has a single function parameter
whose type is a class template specialization where the template arguments
are the corresponding template parameters from the function template
for each template argument
in the <i ><a href='temp.names#nt:template-argument-list'>template-argument-list</a></i>
of the <i ><a href='temp.names#nt:simple-template-id'>simple-template-id</a></i>
of the partial specialization<a class='hidden_link' href='#temp.class.order-1.2.sentence-1'>.</a></div></li></ul></div></div><div class='para' id='temp.class.order-2'><div class='marginalizedparent'><a class='marginalized' href='#temp.class.order-2'>2</a></div><div class='sourceLinkParent'><a class='sourceLink' href='https://github.com/Eelis/draft73ca144c7e48612fe72742f9f6a5ec9ad6a934d2/source/templates.tex#L3267'>#</a></div><div id='temp.class.order-2.example-1' class='example'>[<span style='white-space:nowrap'> </span><a class='example_link' href='#temp.class.order-2.example-1'><span class='textit'>Example</span></a><div class='exampleBody'><span class='textit'>:</span> <pre class='codeblock'>
<span class='keyword'>template</span><span class='anglebracket'>&lt;</span><span class='keyword'>int</span> I, <span class='keyword'>int</span> J, <span class='keyword'>class</span> T<span class='anglebracket'>&gt;</span> <span class='keyword'>class</span> X <span class='curlybracket'>{</span> <span class='curlybracket'>}</span>;
<span class='keyword'>template</span><span class='anglebracket'>&lt;</span><span class='keyword'>int</span> I, <span class='keyword'>int</span> J<span class='anglebracket'>&gt;</span>          <span class='keyword'>class</span> X<span class='anglebracket'>&lt;</span>I, J, <span class='keyword'>int</span><span class='anglebracket'>&gt;</span> <span class='curlybracket'>{</span> <span class='curlybracket'>}</span>;         <span class='comment'>// #1</span>
<span class='keyword'>template</span><span class='anglebracket'>&lt;</span><span class='keyword'>int</span> I<span class='anglebracket'>&gt;</span>                 <span class='keyword'>class</span> X<span class='anglebracket'>&lt;</span>I, I, <span class='keyword'>int</span><span class='anglebracket'>&gt;</span> <span class='curlybracket'>{</span> <span class='curlybracket'>}</span>;         <span class='comment'>// #2</span>

<span class='keyword'>template</span><span class='anglebracket'>&lt;</span><span class='keyword'>int</span> I0, <span class='keyword'>int</span> J0<span class='anglebracket'>&gt;</span> <span class='keyword'>void</span> f<span class='parenthesis'>(</span>X<span class='anglebracket'>&lt;</span>I0, J0, <span class='keyword'>int</span><span class='anglebracket'>&gt;</span><span class='parenthesis'>)</span>;                <span class='comment'>// A</span>
<span class='keyword'>template</span><span class='anglebracket'>&lt;</span><span class='keyword'>int</span> I0<span class='anglebracket'>&gt;</span>         <span class='keyword'>void</span> f<span class='parenthesis'>(</span>X<span class='anglebracket'>&lt;</span>I0, I0, <span class='keyword'>int</span><span class='anglebracket'>&gt;</span><span class='parenthesis'>)</span>;                <span class='comment'>// B</span>

<span class='keyword'>template</span> <span class='anglebracket'>&lt;</span><span class='keyword'>auto</span> v<span class='anglebracket'>&gt;</span>    <span class='keyword'>class</span> Y <span class='curlybracket'>{</span> <span class='curlybracket'>}</span>;
<span class='keyword'>template</span> <span class='anglebracket'>&lt;</span><span class='keyword'>auto</span><span class='operator'>*</span> p<span class='anglebracket'>&gt;</span>   <span class='keyword'>class</span> Y<span class='anglebracket'>&lt;</span>p<span class='anglebracket'>&gt;</span> <span class='curlybracket'>{</span> <span class='curlybracket'>}</span>;                            <span class='comment'>// #3</span>
<span class='keyword'>template</span> <span class='anglebracket'>&lt;</span><span class='keyword'>auto</span><span class='operator'>*</span><span class='operator'>*</span> pp<span class='anglebracket'>&gt;</span> <span class='keyword'>class</span> Y<span class='anglebracket'>&lt;</span>pp<span class='anglebracket'>&gt;</span> <span class='curlybracket'>{</span> <span class='curlybracket'>}</span>;                           <span class='comment'>// #4</span>

<span class='keyword'>template</span> <span class='anglebracket'>&lt;</span><span class='keyword'>auto</span><span class='operator'>*</span> p0<span class='anglebracket'>&gt;</span>   <span class='keyword'>void</span> g<span class='parenthesis'>(</span>Y<span class='anglebracket'>&lt;</span>p0<span class='anglebracket'>&gt;</span><span class='parenthesis'>)</span>;                            <span class='comment'>// C</span>
<span class='keyword'>template</span> <span class='anglebracket'>&lt;</span><span class='keyword'>auto</span><span class='operator'>*</span><span class='operator'>*</span> pp0<span class='anglebracket'>&gt;</span> <span class='keyword'>void</span> g<span class='parenthesis'>(</span>Y<span class='anglebracket'>&lt;</span>pp0<span class='anglebracket'>&gt;</span><span class='parenthesis'>)</span>;                           <span class='comment'>// D</span>
</pre><div id='temp.class.order-2.sentence-1' class='sentence'>According to the ordering rules for function templates,
the function template
<span class='textit'>B</span>
is more specialized than the function template
<span class='textit'>A</span>
and
the function template
<span class='textit'>D</span>
is more specialized than the function template
<span class='textit'>C</span><a class='hidden_link' href='#temp.class.order-2.sentence-1'>.</a></div> <div id='temp.class.order-2.sentence-2' class='sentence'>Therefore, the partial specialization #2
is more specialized than the partial specialization #1
and the partial specialization #4
is more specialized than the partial specialization #3<a class='hidden_link' href='#temp.class.order-2.sentence-2'>.</a></div> —<span style='white-space:nowrap'> </span><i>end example</i></div><span style='white-space:nowrap'> </span>]</div>  <div id='temp.class.order-2.example-2' class='example'>[<span style='white-space:nowrap'> </span><a class='example_link' href='#temp.class.order-2.example-2'><span class='textit'>Example</span></a><div class='exampleBody'><span class='textit'>:</span> <pre class='codeblock'>
<span class='keyword'>template</span><span class='anglebracket'>&lt;</span><span class='keyword'>typename</span> T<span class='anglebracket'>&gt;</span> <span class='keyword'>concept</span> C <span class='operator'>=</span> <span class='keyword'>requires</span> <span class='parenthesis'>(</span>T t<span class='parenthesis'>)</span> <span class='curlybracket'>{</span> t<span class='operator'>.</span>f<span class='parenthesis'>(</span><span class='parenthesis'>)</span>; <span class='curlybracket'>}</span>;
<span class='keyword'>template</span><span class='anglebracket'>&lt;</span><span class='keyword'>typename</span> T<span class='anglebracket'>&gt;</span> <span class='keyword'>concept</span> D <span class='operator'>=</span> C<span class='anglebracket'>&lt;</span>T<span class='anglebracket'>&gt;</span> <span class='operator'>&amp;</span><span class='operator'>&amp;</span> <span class='keyword'>requires</span> <span class='parenthesis'>(</span>T t<span class='parenthesis'>)</span> <span class='curlybracket'>{</span> t<span class='operator'>.</span>f<span class='parenthesis'>(</span><span class='parenthesis'>)</span>; <span class='curlybracket'>}</span>;

<span class='keyword'>template</span><span class='anglebracket'>&lt;</span><span class='keyword'>typename</span> T<span class='anglebracket'>&gt;</span> <span class='keyword'>class</span> S <span class='curlybracket'>{</span> <span class='curlybracket'>}</span>;
<span class='keyword'>template</span><span class='anglebracket'>&lt;</span>C T<span class='anglebracket'>&gt;</span> <span class='keyword'>class</span> S<span class='anglebracket'>&lt;</span>T<span class='anglebracket'>&gt;</span> <span class='curlybracket'>{</span> <span class='curlybracket'>}</span>;   <span class='comment'>// #1</span>
<span class='keyword'>template</span><span class='anglebracket'>&lt;</span>D T<span class='anglebracket'>&gt;</span> <span class='keyword'>class</span> S<span class='anglebracket'>&lt;</span>T<span class='anglebracket'>&gt;</span> <span class='curlybracket'>{</span> <span class='curlybracket'>}</span>;   <span class='comment'>// #2</span>

<span class='keyword'>template</span><span class='anglebracket'>&lt;</span>C T<span class='anglebracket'>&gt;</span> <span class='keyword'>void</span> f<span class='parenthesis'>(</span>S<span class='anglebracket'>&lt;</span>T<span class='anglebracket'>&gt;</span><span class='parenthesis'>)</span>;     <span class='comment'>// A</span>
<span class='keyword'>template</span><span class='anglebracket'>&lt;</span>D T<span class='anglebracket'>&gt;</span> <span class='keyword'>void</span> f<span class='parenthesis'>(</span>S<span class='anglebracket'>&lt;</span>T<span class='anglebracket'>&gt;</span><span class='parenthesis'>)</span>;     <span class='comment'>// B</span>
</pre> <div id='temp.class.order-2.sentence-3' class='sentence'>
The partial specialization #2 is more specialized than #1
because <span class='texttt'>B</span> is more specialized than <span class='texttt'>A</span><a class='hidden_link' href='#temp.class.order-2.sentence-3'>.</a></div> —<span style='white-space:nowrap'> </span><i>end example</i></div><span style='white-space:nowrap'> </span>]</div> </div></div><div id='mfunc' class='section'><h4 ><a class='secnum' href='#mfunc' style='min-width:118pt'>12.6.5.3</a> Members of class template specializations <a class='abbr_ref' href='temp.class.spec.mfunc'>[temp.class.spec.mfunc]</a></h4><div class='para' id='mfunc-1'><div class='marginalizedparent'><a class='marginalized' href='#mfunc-1'>1</a></div><div class='sourceLinkParent'><a class='sourceLink' href='https://github.com/Eelis/draft73ca144c7e48612fe72742f9f6a5ec9ad6a934d2/source/templates.tex#L3318'>#</a></div><div id='mfunc-1.sentence-1' class='sentence'>The template parameter list of a member of a class template partial
specialization shall match the template parameter list of the class template
partial specialization<a class='hidden_link' href='#mfunc-1.sentence-1'>.</a></div> <div id='mfunc-1.sentence-2' class='sentence'>The template argument list of a member of a class template partial
specialization shall match the template argument list of the class template
partial specialization<a class='hidden_link' href='#mfunc-1.sentence-2'>.</a></div> <div id='mfunc-1.sentence-3' class='sentence'>A class template specialization is a distinct template<a class='hidden_link' href='#mfunc-1.sentence-3'>.</a></div> <div id='mfunc-1.sentence-4' class='sentence'>The members of the class template partial specialization are
unrelated to the members of the primary template<a class='hidden_link' href='#mfunc-1.sentence-4'>.</a></div> <div id='mfunc-1.sentence-5' class='sentence'>Class template partial specialization members that are used in a way that
requires a definition shall be defined; the definitions of members of the
primary template are never used as definitions for members of a class
template partial specialization<a class='hidden_link' href='#mfunc-1.sentence-5'>.</a></div> <div id='mfunc-1.sentence-6' class='sentence'>An explicit specialization of a member of a class template partial
specialization is declared in the same way as an explicit specialization of
the primary template<a class='hidden_link' href='#mfunc-1.sentence-6'>.</a></div> <div id='mfunc-1.example-1' class='example'>[<span style='white-space:nowrap'> </span><a class='example_link' href='#mfunc-1.example-1'><span class='textit'>Example</span></a><div class='exampleBody'><span class='textit'>:</span> <pre class='codeblock'>
<span class='comment'>// primary class template</span>
<span class='keyword'>template</span><span class='anglebracket'>&lt;</span><span class='keyword'>class</span> T, <span class='keyword'>int</span> I<span class='anglebracket'>&gt;</span> <span class='keyword'>struct</span> A <span class='curlybracket'>{</span>
  <span class='keyword'>void</span> f<span class='parenthesis'>(</span><span class='parenthesis'>)</span>;
<span class='curlybracket'>}</span>;

<span class='comment'>// member of primary class template</span>
<span class='keyword'>template</span><span class='anglebracket'>&lt;</span><span class='keyword'>class</span> T, <span class='keyword'>int</span> I<span class='anglebracket'>&gt;</span> <span class='keyword'>void</span> A<span class='anglebracket'>&lt;</span>T,I<span class='anglebracket'>&gt;</span><span class='operator'>:</span><span class='operator'>:</span>f<span class='parenthesis'>(</span><span class='parenthesis'>)</span> <span class='curlybracket'>{</span> <span class='curlybracket'>}</span>

<span class='comment'>// class template partial specialization</span>
<span class='keyword'>template</span><span class='anglebracket'>&lt;</span><span class='keyword'>class</span> T<span class='anglebracket'>&gt;</span> <span class='keyword'>struct</span> A<span class='anglebracket'>&lt;</span>T,<span class='literal'>2</span><span class='anglebracket'>&gt;</span> <span class='curlybracket'>{</span>
  <span class='keyword'>void</span> f<span class='parenthesis'>(</span><span class='parenthesis'>)</span>;
  <span class='keyword'>void</span> g<span class='parenthesis'>(</span><span class='parenthesis'>)</span>;
  <span class='keyword'>void</span> h<span class='parenthesis'>(</span><span class='parenthesis'>)</span>;
<span class='curlybracket'>}</span>;

<span class='comment'>// member of class template partial specialization</span>
<span class='keyword'>template</span><span class='anglebracket'>&lt;</span><span class='keyword'>class</span> T<span class='anglebracket'>&gt;</span> <span class='keyword'>void</span> A<span class='anglebracket'>&lt;</span>T,<span class='literal'>2</span><span class='anglebracket'>&gt;</span><span class='operator'>:</span><span class='operator'>:</span>g<span class='parenthesis'>(</span><span class='parenthesis'>)</span> <span class='curlybracket'>{</span> <span class='curlybracket'>}</span>

<span class='comment'>// explicit specialization</span>
<span class='keyword'>template</span><span class='anglebracket'>&lt;</span><span class='anglebracket'>&gt;</span> <span class='keyword'>void</span> A<span class='anglebracket'>&lt;</span><span class='keyword'>char</span>,<span class='literal'>2</span><span class='anglebracket'>&gt;</span><span class='operator'>:</span><span class='operator'>:</span>h<span class='parenthesis'>(</span><span class='parenthesis'>)</span> <span class='curlybracket'>{</span> <span class='curlybracket'>}</span>

<span class='keyword'>int</span> main<span class='parenthesis'>(</span><span class='parenthesis'>)</span> <span class='curlybracket'>{</span>
  A<span class='anglebracket'>&lt;</span><span class='keyword'>char</span>,<span class='literal'>0</span><span class='anglebracket'>&gt;</span> a0;
  A<span class='anglebracket'>&lt;</span><span class='keyword'>char</span>,<span class='literal'>2</span><span class='anglebracket'>&gt;</span> a2;
  a0<span class='operator'>.</span>f<span class='parenthesis'>(</span><span class='parenthesis'>)</span>;           <span class='comment'>// OK, uses definition of primary template's member</span>
  a2<span class='operator'>.</span>g<span class='parenthesis'>(</span><span class='parenthesis'>)</span>;           <span class='comment'>// OK, uses definition of partial specialization's member</span>
  a2<span class='operator'>.</span>h<span class='parenthesis'>(</span><span class='parenthesis'>)</span>;           <span class='comment'>// OK, uses definition of explicit specialization's member</span>
  a2<span class='operator'>.</span>f<span class='parenthesis'>(</span><span class='parenthesis'>)</span>;           <span class='comment'>// ill-formed, no definition of <span class='tcode_in_codeblock'>f</span> for <span class='tcode_in_codeblock'>A&lt;T,2&gt;</span>; the primary template is not used here</span>
<span class='curlybracket'>}</span>
</pre> —<span style='white-space:nowrap'> </span><i>end example</i></div><span style='white-space:nowrap'> </span>]</div> </div><div class='para' id='mfunc-2'><div class='marginalizedparent'><a class='marginalized' href='#mfunc-2'>2</a></div><div class='sourceLinkParent'><a class='sourceLink' href='https://github.com/Eelis/draft73ca144c7e48612fe72742f9f6a5ec9ad6a934d2/source/templates.tex#L3370'>#</a></div><div id='mfunc-2.sentence-1' class='sentence'>If a member template of a class template is partially specialized,
the member template partial specializations are member templates of
the enclosing class template;
if the enclosing class template is instantiated (<a href='temp.inst'>[temp.inst]</a>, <a href='temp.explicit'>[temp.explicit]</a>),
a declaration for every member template partial specialization is also
instantiated as part of creating the members of the class template
specialization<a class='hidden_link' href='#mfunc-2.sentence-1'>.</a></div> <div id='mfunc-2.sentence-2' class='sentence'>If the primary member template is explicitly specialized for a given
(implicit) specialization of the enclosing class template,
the partial specializations of the member template are ignored for this
specialization of the enclosing class template<a class='hidden_link' href='#mfunc-2.sentence-2'>.</a></div> <div id='mfunc-2.sentence-3' class='sentence'>If a partial specialization of the member template is explicitly specialized
for a given (implicit) specialization of the enclosing class template,
the primary member template and its other partial specializations are
still considered for this specialization of the enclosing class template<a class='hidden_link' href='#mfunc-2.sentence-3'>.</a></div> <div id='mfunc-2.example-1' class='example'>[<span style='white-space:nowrap'> </span><a class='example_link' href='#mfunc-2.example-1'><span class='textit'>Example</span></a><div class='exampleBody'><span class='textit'>:</span> <pre class='codeblock'>
<span class='keyword'>template</span><span class='anglebracket'>&lt;</span><span class='keyword'>class</span> T<span class='anglebracket'>&gt;</span> <span class='keyword'>struct</span> A <span class='curlybracket'>{</span>
  <span class='keyword'>template</span><span class='anglebracket'>&lt;</span><span class='keyword'>class</span> T2<span class='anglebracket'>&gt;</span> <span class='keyword'>struct</span> B <span class='curlybracket'>{</span><span class='curlybracket'>}</span>;                     <span class='comment'>// #1</span>
  <span class='keyword'>template</span><span class='anglebracket'>&lt;</span><span class='keyword'>class</span> T2<span class='anglebracket'>&gt;</span> <span class='keyword'>struct</span> B<span class='anglebracket'>&lt;</span>T2<span class='operator'>*</span><span class='anglebracket'>&gt;</span> <span class='curlybracket'>{</span><span class='curlybracket'>}</span>;                <span class='comment'>// #2</span>
<span class='curlybracket'>}</span>;

<span class='keyword'>template</span><span class='anglebracket'>&lt;</span><span class='anglebracket'>&gt;</span> <span class='keyword'>template</span><span class='anglebracket'>&lt;</span><span class='keyword'>class</span> T2<span class='anglebracket'>&gt;</span> <span class='keyword'>struct</span> A<span class='anglebracket'>&lt;</span><span class='keyword'>short</span><span class='anglebracket'>&gt;</span><span class='operator'>:</span><span class='operator'>:</span>B <span class='curlybracket'>{</span><span class='curlybracket'>}</span>;  <span class='comment'>// #3</span>

A<span class='anglebracket'>&lt;</span><span class='keyword'>char</span><span class='anglebracket'>&gt;</span><span class='operator'>:</span><span class='operator'>:</span>B<span class='anglebracket'>&lt;</span><span class='keyword'>int</span><span class='operator'>*</span><span class='anglebracket'>&gt;</span>  abcip;                              <span class='comment'>// uses #2</span>
A<span class='anglebracket'>&lt;</span><span class='keyword'>short</span><span class='anglebracket'>&gt;</span><span class='operator'>:</span><span class='operator'>:</span>B<span class='anglebracket'>&lt;</span><span class='keyword'>int</span><span class='operator'>*</span><span class='anglebracket'>&gt;</span> absip;                              <span class='comment'>// uses #3</span>
A<span class='anglebracket'>&lt;</span><span class='keyword'>char</span><span class='anglebracket'>&gt;</span><span class='operator'>:</span><span class='operator'>:</span>B<span class='anglebracket'>&lt;</span><span class='keyword'>int</span><span class='anglebracket'>&gt;</span>  abci;                                <span class='comment'>// uses #1</span>
</pre> —<span style='white-space:nowrap'> </span><i>end example</i></div><span style='white-space:nowrap'> </span>]</div> </div></div></div></body></html>