如何使用variadic模板参数填充带有typeid的向量

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 填充向量.我怎么能实现这个?

Con*_*tor 7

以下解决方案使用intializer列表:

template <typename... Types>
void Fill(std::vector<std::type_index>& vec)
{
    vec.insert(vec.end(), {typeid(Types)...});
}
Run Code Online (Sandbox Code Playgroud)

查看实例.