Skip to content

[temp.arg.template] Clean up wording for template template argument matching #6804

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
86 changes: 46 additions & 40 deletions source/templates.tex
Original file line number Diff line number Diff line change
Expand Up @@ -1351,25 +1351,60 @@
\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}.
Two template parameters match if they are of the same kind (type, non-type, template),
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 T> class A { @\commentellip@ };
Expand All @@ -1389,6 +1424,8 @@
Z<D> zd; // OK
\end{codeblock}
\end{example}

\pnum
\begin{example}
\begin{codeblock}
template <class T> struct eval;
Expand All @@ -1409,6 +1446,8 @@
eval<E<int, float>> eE; // error: \tcode{E} does not match \tcode{TT} in partial specialization
\end{codeblock}
\end{example}

\pnum
\begin{example}
\begin{codeblock}
template<typename T> concept C = requires (T t) { t.f(); };
Expand All @@ -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}
Expand Down