【发布时间】:2014-08-17 17:03:48
【问题描述】:
我不确定我是否以最有效的方式表达了这个问题,但我现在才开始使用 C++11,并且无法将其新功能应用于手头的问题。我有以下名义功能:
template <typename ... Args>
std::vector<std::type_index> foo()
我希望foo() 返回一个vector,其中包含参数包Args 中每种类型的type_index 值。例如,foo<int, vector<int>, double>() 将返回一个包含{ type_index(typeid(int)), type_index(typeid(vector<int>)), type_index(typeid(double)) } 的vector。
理论上,我想遍历包中的类型并在每个类型上调用上述转换(即给定类型T,返回type_index(typeid(T))。
我觉得应该有一种干净的方法来完成这项工作,但我不清楚如何操作可变参数模板机制来完成这项工作。我的直觉正确吗?
【问题讨论】:
标签: c++ templates c++11 variadic-templates typeinfo