在标准中,模板参数的语法在哪里定义,例如,'std::function<int(char)>'?

Where in the standard is the grammar for the template argument in, e.g., `std::function<int(char)>` defined?

本文关键字:int lt function char gt std 标准 语法 参数 在哪里 定义      更新时间:2023-10-16

只是出于好奇和教育原因,我试图在C++标准中找到它定义int(char)std::function<int(char)>有效的地方。搜索单词模板、参数、函数、函数类型等的任何排列并不是特别容易。我能放在一起的最好的定义是template instantiation template argument function type specifier...

类型名称是一个声明,没有声明的名义事物的名称,就像可以在函数声明中显示为参数一样。模板参数可以是这样的类型 ID

它在[decl.name]中,作为type-id的产物之一

[ 示例:

int                 // int i
int *               // int *pi
int *[3]            // int *p[3]
int (*)[3]          // int (*p3i)[3]
int *()             // int *f()
int (*)(double)     // int (*pf)(double)

分别命名类型"int"、"指向int的指针"、"指向int的 3 个指针数组"、"指向 3 个int数组的指针"、"返回指向int的函数(无参数(的函数"和"指向 (double( 返回int的函数的指针"。— 结束示例 ]

int(char)读作"(char(返回int的函数">