#include <iostream>
#include <type_traits>
template <int Arg>
void foo()
{
std::cout << Arg << ' ';
}
template <int First, int... Rest, typename T = std::enable_if_t<(sizeof...(Rest) > 0)>>
void foo()
{
std::cout << First << ' ';
foo<Rest...>();
}
int main()
{
foo<1, 2, 3>();
foo<1, 2, 3, bool>();
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8dHlwZV90cmFpdHM+Cgp0ZW1wbGF0ZSA8aW50IEFyZz4Kdm9pZCBmb28oKQp7CglzdGQ6OmNvdXQgPDwgQXJnIDw8ICcgJzsKfQoKdGVtcGxhdGUgPGludCBGaXJzdCwgaW50Li4uIFJlc3QsIHR5cGVuYW1lIFQgPSBzdGQ6OmVuYWJsZV9pZl90PChzaXplb2YuLi4oUmVzdCkgPiAwKT4+CnZvaWQgZm9vKCkKewoJc3RkOjpjb3V0IDw8IEZpcnN0IDw8ICcgJzsKCWZvbzxSZXN0Li4uPigpOwp9CgppbnQgbWFpbigpCnsKCWZvbzwxLCAyLCAzPigpOwoJZm9vPDEsIDIsIDMsIGJvb2w+KCk7CgoJcmV0dXJuIDA7Cn0=
prog.cpp: In function ‘int main()’:
prog.cpp:20:21: error: no matching function for call to ‘foo()’
foo<1, 2, 3, bool>();
^
prog.cpp:5:6: note: candidate: template<int Arg> void foo()
void foo()
^~~
prog.cpp:5:6: note: template argument deduction/substitution failed:
prog.cpp:20:21: error: wrong number of template arguments (4, should be 1)
foo<1, 2, 3, bool>();
^
prog.cpp:11:6: note: candidate: template<int First, int ...Rest, class T> void foo()
void foo()
^~~
prog.cpp:11:6: note: template argument deduction/substitution failed: