I'm new to template metaprogramming. I was looking for a metafunction to check if parameter pack arguments are of a certain type (C++11 required). For this I use:
template<typename ...Ts>
void foo(Ts... args)
{
static_assert(is_all_same<int, Ts...>::value, "Arguments must be of type int");
// do something
}
I was thinking about using std::is_same
as a template (pun intended) add the functionality for parameter packs. This is what I have right now:
template<typename T, typename... U>
struct is_all_same : std::false_type {};
template<typename T>
struct is_all_same<T, T...> : std::true_type {};
But it doesn't work. gcc says:
<source>:323:24: error: expansion pattern 'T' contains no parameter packs
323 | struct is_all_same<T, T...> : std::true_type {};
What I don't understand is how to add specialisation for a parameter pack. Do I have to use recursion somehow?