虽然我的最终用例不同,但我基本上想解决这个问题:
// Assumption: Length of the Fields is same as that of vector.
template<typename... Fields>
void Increment(const string &name, const std::vector<string> &fields) {
// *** How do I implement this function so that I can call something like:
// SpecializedCounter<typeof(Fields)...> counter = new Counter<typeof(fields)>();
// counter->Increment(name, field_pack);
}
template <typename... Fields>
class SpecializedCounter : public Counter<Fields...> {
// public Counter provides a generalized interface for how to increment the counters.
void Increment(const string &name, const Fields... &fields) {
// I know how to implement this.
}
};
问题的关键是,如何将列表/向量或可迭代类型转换为参数包。如果这个问题是双重的,我会很高兴的! :)