对于 c++20,建议为通用 lambdas p0428r2.pdf添加以下语法
auto f = []<typename T>( T t ) {};
但是 gcc 8 中的当前实现不接受以下实例化:
f<std::string>("");
这是 gcc 中的实现错误还是缺少语言功能?我知道我们谈论的是提案而不是批准的规范。
完整示例(与模板函数语法比较):
template <typename T> void n( T t ) { std::cout << t << std::endl; }
auto f = []<typename T>( T t ) { std::cout << t << std::endl; };
int main()
{
f<std::string>("Hello"); // error!
n<std::string>("World");
}
抱怨以下错误:
main.cpp:25:22: 错误:'>' 标记 f("Hello") 之前的预期主表达式;