Date: Tue, 7 Jun 2022 23:15:58 +0530
I was reading temp.arg.explicit
<https://timsong-cpp.github.io/cppwp/n4868/temp.arg.explicit#4> and noticed
that there may be some defect in the wording there. In particular, it
currently says:
*" Trailing template arguments that can be deduced
<https://timsong-cpp.github.io/cppwp/n4868/temp.deduct> or obtained from
default template-argument
<https://timsong-cpp.github.io/cppwp/n4868/temp.names#nt:template-argument>s
may be omitted from the list of explicit template-argument
<https://timsong-cpp.github.io/cppwp/n4868/temp.names#nt:template-argument>s.
<https://timsong-cpp.github.io/cppwp/n4868/temp.arg.explicit#4.sentence-1>*
*A trailing template parameter pack ([temp.variadic]
<https://timsong-cpp.github.io/cppwp/n4868/temp.variadic>) not otherwise
deduced will be deduced as an empty sequence of template arguments.
<https://timsong-cpp.github.io/cppwp/n4868/temp.arg.explicit#4.sentence-2>*
*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.
<https://timsong-cpp.github.io/cppwp/n4868/temp.arg.explicit#4.sentence-3>
"*
*(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 means according to the current wording(sentence 3 quoted above) the
following should be invalid:
template<typename T = int>
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.
*Resolution:*
The simplest resolution is to change the 3rd sentence quoted above to the
following:
*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 <> itself may also be omitted.
<https://timsong-cpp.github.io/cppwp/n4868/temp.arg.explicit#4.sentence-3>*
*(end resolution)*
*I have highlighted the addition/change that i made in the above sentence
to make it more clear/easily visible.*
<https://timsong-cpp.github.io/cppwp/n4868/temp.arg.explicit#4> and noticed
that there may be some defect in the wording there. In particular, it
currently says:
*" Trailing template arguments that can be deduced
<https://timsong-cpp.github.io/cppwp/n4868/temp.deduct> or obtained from
default template-argument
<https://timsong-cpp.github.io/cppwp/n4868/temp.names#nt:template-argument>s
may be omitted from the list of explicit template-argument
<https://timsong-cpp.github.io/cppwp/n4868/temp.names#nt:template-argument>s.
<https://timsong-cpp.github.io/cppwp/n4868/temp.arg.explicit#4.sentence-1>*
*A trailing template parameter pack ([temp.variadic]
<https://timsong-cpp.github.io/cppwp/n4868/temp.variadic>) not otherwise
deduced will be deduced as an empty sequence of template arguments.
<https://timsong-cpp.github.io/cppwp/n4868/temp.arg.explicit#4.sentence-2>*
*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.
<https://timsong-cpp.github.io/cppwp/n4868/temp.arg.explicit#4.sentence-3>
"*
*(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 means according to the current wording(sentence 3 quoted above) the
following should be invalid:
template<typename T = int>
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.
*Resolution:*
The simplest resolution is to change the 3rd sentence quoted above to the
following:
*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 <> itself may also be omitted.
<https://timsong-cpp.github.io/cppwp/n4868/temp.arg.explicit#4.sentence-3>*
*(end resolution)*
*I have highlighted the addition/change that i made in the above sentence
to make it more clear/easily visible.*
Received on 2022-06-07 17:46:10