gpt4 book ai didi

c++ - 函数的类型是否受其参数声明子句中是否存在函数参数包的影响?

转载 作者:行者123 更新时间:2023-12-05 05:40:33 24 4
gpt4 key购买 nike

考虑以下几点:

#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指定函数的参数类型列表是函数类型的一部分(显然):

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.

[dcl.fct]/5的最后一句指定“函数参数包的存在或不存在”是函数的参数类型列表的一部分:

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.

由于非模板函数 f 在其参数列表中没有函数参数包,但可变参数函数模板 g 有,这是否意味着它们的参数类型-列表不同,因此它们的类型也不同?

最佳答案

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是一个 Abbreviated Function Template .作为模板,它没有自己的类型。

g<int> ,另一方面,是 g实例化 .它产生一个具体的函数 void g(int) , 与 f 具有相同的类型.

关于c++ - 函数的类型是否受其参数声明子句中是否存在函数参数包的影响?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/72384749/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com