f(T&()) 的模板参数推导是如何发生的?
How does template argument deduction for f(T&()) happen?
我正在阅读标准,无法弄清楚以下代码是如何编译的。
template <class T>
void f(T&()) {}
double d = 0;
double& g() { return d; }
int main() {
f(g);
}
[temp.deduct.type]/8提供扣款发生的情况列表:
A template type argument T, a template template argument TT or a template non-type argument i can be deduced if P and A have one of the following forms:
T
cv T
T*
T&
T&&
...
对于我的 P = T&()
,它似乎与列表中的任何形式都不匹配。
我是否遗漏了任何模板推导规则,或者列表不全面?
中对此进行了介绍
These forms can be used in the same way as T
is for further composition of types.
如果您使用与 T
不同的类型名称编写模板,可能会更清楚,例如
template <class U>
void f(U&()) {}
所以现在您可以看到 U&()
的形式是 T()
,其中 U&
是 T&
的变体。
我正在阅读标准,无法弄清楚以下代码是如何编译的。
template <class T>
void f(T&()) {}
double d = 0;
double& g() { return d; }
int main() {
f(g);
}
[temp.deduct.type]/8提供扣款发生的情况列表:
A template type argument T, a template template argument TT or a template non-type argument i can be deduced if P and A have one of the following forms:
T
cv T
T*
T&
T&&
...
对于我的 P = T&()
,它似乎与列表中的任何形式都不匹配。
我是否遗漏了任何模板推导规则,或者列表不全面?
These forms can be used in the same way as
T
is for further composition of types.
如果您使用与 T
不同的类型名称编写模板,可能会更清楚,例如
template <class U>
void f(U&()) {}
所以现在您可以看到 U&()
的形式是 T()
,其中 U&
是 T&
的变体。