From c8f2d64cec1acaf301f0b15e276db4f1d38ba2e4 Mon Sep 17 00:00:00 2001 From: Anoop Rana <93918384+ranaanoop@users.noreply.github.com> Date: Wed, 8 Jun 2022 01:16:43 +0530 Subject: [PATCH 1/5] Fixed wording regarding omitting the template argument list <> I was reading [temp.arg.explicit] and noticed that there may be some defect in the wording there. In particular, it currently says: " Trailing template arguments that can be deduced or obtained from default template-arguments may be omitted from the list of explicit template-arguments. A trailing template parameter pack ([temp.variadic]) not otherwise deduced will be deduced as an empty sequence of template arguments. If all of the template arguments can be deduced, they may all be omitted; in this case, the empty template argument list <> itself may also be omitted. " (emphasis mine) Note carefully, in the last statement it says that when all of the template arguments can be deduced then they may all be omitted and in this case the empty <> itself may also be omitted. This is an issue because it does not mention that we can also omit the empty <> when all of the template arguments can be obtained from the default template arguments. Since deducing arguments and using default values are two different things, there should be a separate mention of the latter. Only in the first sentence(quoted above) there is a mention of default template arguments but that is only in the context of the list of explicit template arguments. This also means that according to the current wording(sentence 3 quoted above) the following should be invalid: template void func() { } int main() { func(); //this should be invalid according to the current wording } But we know that the above is not invalid and so there should be changes made to the sentence 3 quoted above to include the case of default template arguments. --- source/templates.tex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/templates.tex b/source/templates.tex index 710ea797f8..7a72a3b1bf 100644 --- a/source/templates.tex +++ b/source/templates.tex @@ -6826,7 +6826,7 @@ A trailing template parameter pack\iref{temp.variadic} not otherwise deduced will be deduced as an empty sequence of template arguments. \end{note} -If all of the template arguments can be deduced, they may all be omitted; +If all of the template arguments can be deduced or obtained from default template arguments, they may all be omitted; in this case, the empty template argument list \tcode{<>} itself may also be omitted. \begin{example} From c8e763fe583dfb3f5d1fd967e398be62e981a1d5 Mon Sep 17 00:00:00 2001 From: Anoop Rana <93918384+ranaanoop@users.noreply.github.com> Date: Wed, 8 Jun 2022 09:37:42 +0530 Subject: [PATCH 2/5] Added example indicating when empty<> can be ommited After the revised wording at https://github.com/cplusplus/draft/pull/5512/files, all of the following should be valid: template void f(T) { } int main() { func(); //calls specialization func auto a = func<>; //\tcode{a} has type void (*)(int) auto b = func; //OK: \tcode{b} has type void (*)(int) } --- source/templates.tex | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/source/templates.tex b/source/templates.tex index 7a72a3b1bf..97fa565c34 100644 --- a/source/templates.tex +++ b/source/templates.tex @@ -6845,6 +6845,18 @@ \end{codeblock} \end{example} +\begin{example} +\begin{codeblock} +template void f(T) { } +int main() +{ + func(); //calls specialization func + auto a = func<>; //\tcode{a} has type void (*)(int) + auto b = func; //OK: \tcode{b} has type void (*)(int) +} +\end{codeblock} +\end{example} + \pnum \begin{note} An empty template argument list can be used to indicate that a given From db1b4f7b60965f29845894009309c80281610a85 Mon Sep 17 00:00:00 2001 From: Anoop Rana <93918384+ranaanoop@users.noreply.github.com> Date: Wed, 8 Jun 2022 10:29:39 +0530 Subject: [PATCH 3/5] Fixed typo made in example indicating when empty<> can be omitted Here a typo made in the example showing when empty<> can be omitted has been fixed. --- source/templates.tex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/templates.tex b/source/templates.tex index 97fa565c34..747124c271 100644 --- a/source/templates.tex +++ b/source/templates.tex @@ -6847,7 +6847,7 @@ \begin{example} \begin{codeblock} -template void f(T) { } +template void func(T) { } int main() { func(); //calls specialization func From 175d5b8988172f87a3ef410e855939422cbea525 Mon Sep 17 00:00:00 2001 From: Anoop Rana <93918384+ranaanoop@users.noreply.github.com> Date: Wed, 8 Jun 2022 23:52:44 +0530 Subject: [PATCH 4/5] Update source/templates.tex MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Added some formatting in description of the example added indicating when empty<> can be omitted Co-authored-by: Johel Ernesto Guerrero Peña --- source/templates.tex | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/source/templates.tex b/source/templates.tex index 747124c271..b71cb5d2dd 100644 --- a/source/templates.tex +++ b/source/templates.tex @@ -6850,9 +6850,9 @@ template void func(T) { } int main() { - func(); //calls specialization func - auto a = func<>; //\tcode{a} has type void (*)(int) - auto b = func; //OK: \tcode{b} has type void (*)(int) + func(); // calls the specialization \tcode{func} + auto a = func<>; // \tcode{a} has type \tcode{void (*)(int)} + auto b = func; // OK: \tcode{b} has type \tcode{void (*)(int)} } \end{codeblock} \end{example} From f026d5af7e65fa937b8115096d7709b5e2d6ffc0 Mon Sep 17 00:00:00 2001 From: Anoop Rana <93918384+ranaanoop@users.noreply.github.com> Date: Thu, 9 Jun 2022 09:55:14 +0530 Subject: [PATCH 5/5] Added default argument so that empty<> can be omitted --- source/templates.tex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/templates.tex b/source/templates.tex index b71cb5d2dd..77cd7a1b25 100644 --- a/source/templates.tex +++ b/source/templates.tex @@ -6847,7 +6847,7 @@ \begin{example} \begin{codeblock} -template void func(T) { } +template void func(T = T{}) { } int main() { func(); // calls the specialization \tcode{func}