From 7e83e394fd1fc15a38642cbaf9bd18f88bcbe19f Mon Sep 17 00:00:00 2001 From: James Touton Date: Mon, 12 Feb 2024 02:15:25 -0800 Subject: [PATCH] [temp.arg.template] Clean up wording for template template argument matching --- source/templates.tex | 86 +++++++++++++++++++++++--------------------- 1 file changed, 46 insertions(+), 40 deletions(-) diff --git a/source/templates.tex b/source/templates.tex index 4671d85c34..bebbc91738 100644 --- a/source/templates.tex +++ b/source/templates.tex @@ -1351,12 +1351,45 @@ \end{example} \pnum -A \grammarterm{template-argument} matches a template +A template \grammarterm{template-argument} \tcode{A} matches a template \grammarterm{template-parameter} \tcode{P} when -\tcode{P} is at least as specialized as the \grammarterm{template-argument} \tcode{A}. -In this comparison, if \tcode{P} is unconstrained, -the constraints on \tcode{A} are not considered. -If \tcode{P} contains a template parameter pack, then \tcode{A} also matches \tcode{P} +\tcode{P} is at least as specialized as \tcode{A}, +ignoring constraints on \tcode{A} +if \tcode{P} is unconstrained. +\tcode{P} is at least as specialized as \tcode{A} +if, given the following rewrite to two function templates, +the function template corresponding to \tcode{P} +is at least as specialized as +the function template corresponding to \tcode{A} +according to the partial ordering rules +for function templates\iref{temp.func.order}. +Given an invented class template \tcode{X} +with the \grammarterm{template-head} of \tcode{A} (including default arguments +and \grammarterm{requires-clause}, if any): + +\begin{itemize} +\item +Each of the two function templates has the same template parameters +and \grammarterm{requires-clause} (if any), +respectively, as \tcode{P} or \tcode{A}. +\item +Each function template has a single function parameter +whose type is a specialization of \tcode{X} +with template arguments corresponding to the template parameters +from the respective function template where, +for each template parameter \tcode{PP} +in the \grammarterm{template-head} of the function template, +a corresponding template argument \tcode{AA} is formed. +If \tcode{PP} declares a template parameter pack, +then \tcode{AA} is the pack expansion \tcode{PP...}\iref{temp.variadic}; +otherwise, \tcode{AA} is the \grammarterm{id-expression} \tcode{PP}. +\end{itemize} +If the rewrite produces an invalid type, +then \tcode{P} is not at least as specialized as \tcode{A}. + +\pnum +If \tcode{P} contains a template parameter pack\iref{temp.variadic}, then +\tcode{A} also matches \tcode{P} if each of \tcode{A}'s template parameters matches the corresponding template parameter in the \grammarterm{template-head} of \tcode{P}. @@ -1364,12 +1397,14 @@ for non-type \grammarterm{template-parameter}{s}, their types are equivalent\iref{temp.over.link}, and for template \grammarterm{template-parameter}{s}, each of their corresponding \grammarterm{template-parameter}{s} matches, recursively. -When \tcode{P}'s \grammarterm{template-head} contains a template parameter -pack\iref{temp.variadic}, the template parameter pack will match zero or more template +A template parameter pack +in the \grammarterm{template-head} of \tcode{P} +will match zero or more template parameters or template parameter packs in the \grammarterm{template-head} of \tcode{A} with the same type and form as the template parameter pack in \tcode{P} (ignoring whether those template parameters are template parameter packs). +\pnum \begin{example} \begin{codeblock} template class A { @\commentellip@ }; @@ -1389,6 +1424,8 @@ Z zd; // OK \end{codeblock} \end{example} + +\pnum \begin{example} \begin{codeblock} template struct eval; @@ -1409,6 +1446,8 @@ eval> eE; // error: \tcode{E} does not match \tcode{TT} in partial specialization \end{codeblock} \end{example} + +\pnum \begin{example} \begin{codeblock} template concept C = requires (T t) { t.f(); }; @@ -1426,39 +1465,6 @@ \end{codeblock} \end{example} -\pnum -A template \grammarterm{template-parameter} \tcode{P} is -at least as specialized as a template \grammarterm{template-argument} \tcode{A} -if, given the following rewrite to two function templates, -the function template corresponding to \tcode{P} -is at least as specialized as -the function template corresponding to \tcode{A} -according to the partial ordering rules -for function templates\iref{temp.func.order}. -Given an invented class template \tcode{X} -with the \grammarterm{template-head} of \tcode{A} (including default arguments -and \grammarterm{requires-clause}, if any): - -\begin{itemize} -\item -Each of the two function templates has the same template parameters -and \grammarterm{requires-clause} (if any), -respectively, as \tcode{P} or \tcode{A}. -\item -Each function template has a single function parameter -whose type is a specialization of \tcode{X} -with template arguments corresponding to the template parameters -from the respective function template where, -for each template parameter \tcode{PP} -in the \grammarterm{template-head} of the function template, -a corresponding template argument \tcode{AA} is formed. -If \tcode{PP} declares a template parameter pack, -then \tcode{AA} is the pack expansion \tcode{PP...}\iref{temp.variadic}; -otherwise, \tcode{AA} is the \grammarterm{id-expression} \tcode{PP}. -\end{itemize} -If the rewrite produces an invalid type, -then \tcode{P} is not at least as specialized as \tcode{A}. - \rSec1[temp.constr]{Template constraints} \rSec2[temp.constr.general]{General}