lundi 5 décembre 2016

Parameter pack inconsistent deduction

void f(int&, int&);
void f(double&, double&, double&);
// some other helper functions with params always lvalue refs

template <typename... Types>
void fun(void(*g)(Types...), Types&&... args) {
 g(args...);
}

int main() {
int x = 1;
int y = 2;
fun(f,x,y);
fun(f, 1, 2);
}

I want to have a function template that calls another helper function with its parameter pack. In the caller function the parameters can be lvalue/rvalue refs but the in the helper function they will always be lvalue refs since they are being passed by the calling function. I don't know how should the first parameter (the type of the helper function pointer) in the caller function should be declared to avoid having this inconsistent type deduction problem.

Aucun commentaire:

Enregistrer un commentaire