mardi 30 août 2016

Inconsistency in function type decay between variadic/non-variadic templates?

Given a non-variadic function template:

template<class T>
void f(void(t)(T));

And a plain function:

void f1(int);

This works:

f(f1);

The type of t becomes void (*)(int).

However, the variadic counterpart:

template<class... T>
void f(void(...t)(T));

does not work. The compilers (gcc & clang) complain about mismatched types void(T) and void (*)(int).

Note that if * is added explicitly, it works as it should:

template<class... T>
void f(void(*...t)(T));

So, why the non-variadic one can decay the function type while the variadic one cannot?

Aucun commentaire:

Enregistrer un commentaire