从vector构造c ++参数包

时间:2014-03-10 19:18:14

标签: c++ templates

虽然我的最终用例不同,但我基本上想解决这个问题:

// 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.
  }

};

问题的关键是,如何将列表/向量或可迭代类型转换为参数包。如果这个问题是双重的,我会很高兴的! :)

0 个答案:

没有答案