【发布时间】:2021-08-05 04:36:10
【问题描述】:
我不明白为什么这不起作用:
template <typename ... Types>
void func()
{
(std::cout << typeid(Types).name(), ...) ; // Syntax error, unexpected token '...', expected 'expression'
(static_assert(std::is_integral_v<Types>, "Type must be integral type"), ...); // Syntax error: unexpected token 'static_assert', expected 'expression'
}
int main()
{
func<int, short>();
}
我的理解是编译器基本上应该去:
(static_assert(std::is_integral_v<Types>, "Error message"), ...)
逗号是一个运算符,对于参数包中的每种类型,应该重复运算符之前的内容。为什么这不起作用?
【问题讨论】:
标签: c++ templates fold-expression