lundi 31 août 2015

Convert arguments of variadic function

This is probably a newbie question but I thought it might be interesting. Let's say I have this function:

template <typename First, typename... T>
int ComputeSomething(const First& f, const T&... t);

I would like to write a second function that calls the one above in the general case, but converts the arguments when First and T are of type float, i.e., it calls a Convert function on each argument:

long Convert(float f);

template <typename First, typename... T>
int MyFun(const First& f, const T&... t) {
  return ComputeSomething(f, t...);
}

// This is what I would like:
int MyFun(const float& f, const float& t...) {
  return ComputeSomething(Convert(f), Convert(t)...);
}

How can I achieve that?

Aucun commentaire:

Enregistrer un commentaire