函数的类型是否受到其参数 - 范围子句中存在或不存在函数参数包的影响?
考虑以下内容:
#include <type_traits>
void f(int);
void g(auto ...);
static_assert(std::is_same_v<decltype(f), decltype(g<int>)>); // succeeds in GCC 12.1, Clang 14.0.0, and MSVC 19.30
[dcl.fct]/12 指定函数的参数类型列表是函数类型的一部分(显然):
返回类型,参数类型list , ref-qualifier , cv-qualifier-seq 和例外规范,但不是默认参数或taffing 需要句子是函数类型的一部分。
最终的转换参数类型的列表以及的存在或不存在 eLLIPSIS或函数参数pack 是函数的 parameter-type-list 。
由于非模板函数f
在其参数列表中没有函数参数包,但是variadic函数模板g
确实如此,这并不意味着他们的参数型列表是不同的,因此他们的类型也是吗?
Consider the following:
#include <type_traits>
void f(int);
void g(auto ...);
static_assert(std::is_same_v<decltype(f), decltype(g<int>)>); // succeeds in GCC 12.1, Clang 14.0.0, and MSVC 19.30
[dcl.fct]/12 specifies that the parameter-type-list of a function is part of the function type (obviously):
The return type, the parameter-type-list, the ref-qualifier, the cv-qualifier-seq, and the exception specification, but not the default arguments or the trailing requires-clause, are part of the function type.
The last sentence of [dcl.fct]/5 specifies that the "presence or absence of ... a function parameter pack" is part of the function's parameter-type-list:
The resulting list of transformed parameter types and the presence or absence of the ellipsis or a function parameter pack is the function's parameter-type-list.
Since the non-template function f
has no function parameter pack in its parameter list but variadic function template g
does, would that not mean that their parameter-type-lists are different, and therefore their types are also?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
g
是 nofollow noreferrer“> abbrevied函数功能模板。作为模板,它没有自己的类型。另一方面,
g&lt; int
是g
的 Intantiation 。它产生一个具体函数void g(int)
,其类型与f
相同。g
is an Abbreviated Function Template. Being a template, it doesn't have a type of its own.g<int>
, on the other hand, is an instantiation ofg
. It produces a concrete functionvoid g(int)
, which has the same type asf
.