<!DOCTYPE html><html lang='en'><head><title>[temp.class.order]</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.order'>[temp.decls]</a></h2><h3 ><a class='secnum' style='min-width:103pt'>12.6.5</a> Class template partial specializations <a class='abbr_ref' href='temp.class.spec#temp.class.order'>[temp.class.spec]</a></h3><h4 ><a class='secnum' style='min-width:118pt'>12.6.5.2</a> Partial ordering of class template specializations <a class='abbr_ref'>[temp.class.order]</a></h4><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#L3243'>#</a></div><div id='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='1.sentence-2' class='sentence'><ul class='itemize'><li id='1.1'><div class='marginalizedparent' style='left:-7em'><a class='marginalized' href='#1.1'>(1.1)</a></div><div id='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='#1.1.sentence-1'>.</a></div></li><li id='1.2'><div class='marginalizedparent' style='left:-7em'><a class='marginalized' href='#1.2'>(1.2)</a></div><div id='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='#1.2.sentence-1'>.</a></div></li></ul></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#L3267'>#</a></div><div id='2.example-1' class='example'>[<span style='white-space:nowrap'> </span><a class='example_link' href='#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='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='#2.sentence-1'>.</a></div> <div id='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='#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='2.example-2' class='example'>[<span style='white-space:nowrap'> </span><a class='example_link' href='#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='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='#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></body></html>