App*_*ell 3 c++ templates typeid variadic-templates
std::vector<std::type_index> vec;
template <typename T1, typename... Tn>
void Fill() {
vec.push_back(typeid(T1));
// fill the vector with the remaining type ids
}
Run Code Online (Sandbox Code Playgroud)
我想用typeid模板参数的s 填充向量.我怎么能实现这个?
以下解决方案使用intializer列表:
template <typename... Types>
void Fill(std::vector<std::type_index>& vec)
{
vec.insert(vec.end(), {typeid(Types)...});
}
Run Code Online (Sandbox Code Playgroud)
查看实例.
| 归档时间: |
|
| 查看次数: |
2033 次 |
| 最近记录: |