可以使用 std::print 打印模板参数包吗? 像这样的东西:
void func(auto... args){
std::print("???", args...);
}
您使用折叠表达式
void func(auto... args)
{
(std::print("{} ", args), ...);
}
去掉尾随空格
void func(auto arg, auto... args)
{
std::print("{}", arg);
(std::print(" {}", args), ...);
}
此外,你应该转发论点
template<typename T, typename... Ts>
void func(T&& arg, Ts&&... args)
{
std::print("{}", std::forward<T>(arg));
(std::print(" {}", std::forward<Ts>)(args)), ...);
}