函数的类型是否受到其参数 - 范围子句中存在或不存在函数参数包的影响?

发布于 2025-02-01 11:58:01 字数 902 浏览 3 评论 0原文

考虑以下内容:

#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 需要句子是函数类型的一部分。

parameter-type-list 的一部分:

最终的转换参数类型的列表以及的存在或不存在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

安人多梦 2025-02-08 11:58:01

由于非模板函数f在其参数列表中没有函数参数包,但是variadic函数模板g确实如此,这并不意味着他们的参数类型 - 列表不同,因此它们的类型也是吗?

g nofollow noreferrer“> abbrevied函数功能模板。作为模板,它没有自己的类型。

另一方面,g&lt; intg Intantiation 。它产生一个具体函数void g(int),其类型与f相同。

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?

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 of g. It produces a concrete function void g(int), which has the same type as f.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文