Date: Thu, 16 Jul 2020 22:36:34 +0800
template<typename T, typename U = T>
struct Test{};
template<typename T>
void func(Test<T> /*#1*/){
}
Consider the above code, at the point of #1, Does the template-id Test<T>
require a template argument for corresponding template parameter U? The
only quote that mentioned default argument in the standard is the
following :
>When a simple-template-id does not name a function, a default
template->argument is **implicitly instantiated** when the value of that
default argument >is needed. [ Example:
>template<typename T, typename U = int> struct S { };
>S* p; // the type of p is S<bool, int>*
>The default argument for U is instantiated to form the type S<bool, int>*.
>— end example ]
However at the point of #1, The specialization of Test<T> is just a part of
a function template definition, that is, there's no instantiation occuring
here. So, the above quote seems to be not suitable for this case.
In the standard, there's a quote explicitly specified when to supply
default arguments as arguments for function call, that is:
> If an initializer-clause is specified in a parameter-declaration this
initializer-clause is used as a default argument. Default arguments will be
used in calls where trailing arguments are missing.
So, Is it necessary to formulate a formally terminology to cover this case?
such as
>A default template-argument is a template-argument ([temp.arg]) specified
after = in a template-parameter. Default arguments will be used in
template-id where trailing arguments are missing and the corresponding
template parameter does not participate in template argument deduction.
struct Test{};
template<typename T>
void func(Test<T> /*#1*/){
}
Consider the above code, at the point of #1, Does the template-id Test<T>
require a template argument for corresponding template parameter U? The
only quote that mentioned default argument in the standard is the
following :
>When a simple-template-id does not name a function, a default
template->argument is **implicitly instantiated** when the value of that
default argument >is needed. [ Example:
>template<typename T, typename U = int> struct S { };
>S* p; // the type of p is S<bool, int>*
>The default argument for U is instantiated to form the type S<bool, int>*.
>— end example ]
However at the point of #1, The specialization of Test<T> is just a part of
a function template definition, that is, there's no instantiation occuring
here. So, the above quote seems to be not suitable for this case.
In the standard, there's a quote explicitly specified when to supply
default arguments as arguments for function call, that is:
> If an initializer-clause is specified in a parameter-declaration this
initializer-clause is used as a default argument. Default arguments will be
used in calls where trailing arguments are missing.
So, Is it necessary to formulate a formally terminology to cover this case?
such as
>A default template-argument is a template-argument ([temp.arg]) specified
after = in a template-parameter. Default arguments will be used in
template-id where trailing arguments are missing and the corresponding
template parameter does not participate in template argument deduction.
Received on 2020-07-16 09:40:09