I am trying to use variadics to convert N
parameters function to 2^N
parameters function. The following snippet compiles happily by clang 3.9
, while nvcc 8.0
(effectively gcc 5.4
) fails miserably with the error:
error: no instance of overloaded function "foo" matches the argument list
code:
template<class... Ts> struct Typelist{};
template <class..., class... Us>
void foo(Typelist<>, Typelist<Us...>, Us... us ){
// do the actual work
}
template <class T, class... Ts, class... Us>
void foo(Typelist<T, Ts...>, Typelist<Us...>, T t, Ts... ts, Us... us){
foo(Typelist<Ts...>{}, Typelist<Us..., Us...>{}
, ts..., us..., (us+t)...);
}
template <class... Ts>
void bar(Ts... ts){
foo(Typelist<Ts...>{}, Typelist<unsigned>{}
, ts..., 0u);
}
called like
int main(int /*argc*/, char */*argv*/[])
{
bar(2u);
bar(2u, 3u, 4u);
return 0;
}
Am I doing something wrong? How do I make it work with gcc
?