Date: Thu, 16 Jul 2020 22:28:34 +0800
Consider the below code:
template<typename...T>
void func(T...args){
}
int main(){
func(1,2.0,'c');
}
there's a rule that applied to it to deduce these template arguments for
this function template (call). It is:
>For a function parameter pack that occurs at the end of the
parameter-declaration-list, deduction is performed for each remaining
argument of the call, taking the type P of the declarator-id of the
function parameter pack as the corresponding function template parameter
type. Each deduction deduces template arguments for subsequent positions in
the template parameter packs expanded by the function parameter pack.
That means for the parameter-declaration T...args, it declares a function
template park, hence the function parameter type that is used to against
the type of function argument is T because ...args is the declarator-id of
this declaration. So, for this function call func(1,2.0,'c'), template
parameter pack T would be the set consists of {int,double,char}.
However, consider the following variant:
template<typename...T>
void func(T...){
}
int main(){
func(1,2.0,'c');
}
There's no declarator-id here, just an abstract-declarator that denote the
..., How would the quote be applied to this case? What's the corresponding
function parameter type here? It seems to be a wording defect for this
case.
template<typename...T>
void func(T...args){
}
int main(){
func(1,2.0,'c');
}
there's a rule that applied to it to deduce these template arguments for
this function template (call). It is:
>For a function parameter pack that occurs at the end of the
parameter-declaration-list, deduction is performed for each remaining
argument of the call, taking the type P of the declarator-id of the
function parameter pack as the corresponding function template parameter
type. Each deduction deduces template arguments for subsequent positions in
the template parameter packs expanded by the function parameter pack.
That means for the parameter-declaration T...args, it declares a function
template park, hence the function parameter type that is used to against
the type of function argument is T because ...args is the declarator-id of
this declaration. So, for this function call func(1,2.0,'c'), template
parameter pack T would be the set consists of {int,double,char}.
However, consider the following variant:
template<typename...T>
void func(T...){
}
int main(){
func(1,2.0,'c');
}
There's no declarator-id here, just an abstract-declarator that denote the
..., How would the quote be applied to this case? What's the corresponding
function parameter type here? It seems to be a wording defect for this
case.
Received on 2020-07-16 09:32:04