【发布时间】:2020-04-14 15:07:26
【问题描述】:
我真的不知道正确的标题是什么,所以请原谅我写的。我认为最好举个例子。
void foo(std::pair<std::string, T>, std::pair<std::string, U>, std::pair<std::string, Z>, ...);
其中 T、U 和 Z 可以是多种类型,但列表中的参数数量是可变的。我知道您可以使用参数包并假设它们沿这条线传递对象,但是当您调用该函数时,您不能调用对聚合初始值设定项。
template<typename ...args>
void foo(args... values);
//the following isn't allowed, cause it doesn't know the type. (this is what I want it to look like)
foo({"hi",5}, {"hello", true});
有没有可能我正在尝试做的事情?任何帮助将不胜感激。
【问题讨论】:
标签: c++ templates variadic-templates template-meta-programming