jeudi 3 novembre 2016

Is this "if e is a pack, then get a template name, otherwise get a variable name" valid or not?

I have tried to construct a case that requires no typename or template, but still yield a variable or template depending on whether a given name t is a function parameter pack or not

template<typename T> struct A { template<int> static void f(int) { } }; 
template<typename...T> struct A<void(T...,...)> { static const int f = 0; }; 
template<typename> using type = int; 

template<typename T> void f(T t) { A<void(type<decltype(t)>...)>::f<0>(1); }

int main() {
   f(1);   
}

The above will refer to the static const int, and do a comparison. The following just has T t changed to be a pack and make f refer to a template, but GCC does not like either

template<typename ...T> void f(T ...t) { A<void(type<decltype(t)>...)>::f<0>(1); }

int main() {
   f(1, 2, 3);   
}

GCC complains for the first

main.cpp:5:68: error: incomplete type 'A<void(type<decltype (t)>, ...)>' used in nested name specifier
 template<typename T> void f(T t) { A<void(type<decltype(t)>...)>::f<0>(1); }

And for the second

 main.cpp:5:74: error: invalid operands of types '<unresolved overloaded function type>' and 'int' to binary 'operator<'
  template<typename ...T> void f(T ...t) { A<void(type<decltype(t)>...)>::f<0>(1); }

Since Clang accepts both variants, I wanted to ask what compiler is correct?

Aucun commentaire:

Enregistrer un commentaire