lundi 23 mai 2016

Meta-iteration over varadic templates arguments

I would like to generalize the following pattern:

template<class A1, class A2, class A3>
class Foo {
protected:
  template<class T>
  void foo(const T& t) {...do stuff...}
public:
  void bar(const A1& a) { foo(a); }
  void bar(const A2& a) { foo(a); }
  void bar(const A3& a) { foo(a); }
};

The above approach does not scale with a number of increasing arguments. So, I'd like to do:

template<class As...>
class Foo {
protected:
  template<class T>
  void foo(const t& a) {...do stuff...}
public:
  for each type A in As declare:
  void bar(const A& a) { foo(a); }
};

Is there a way to do it?

Aucun commentaire:

Enregistrer un commentaire