I want to write a helper template that checks if a template parameter pack has a common type, i.e., if applying std::common_type
to the pack defines a type.
Using std::void_t with SFINAE I came up with the following definition:
template<typename... Types, typename Enable = void>
struct has_common_type : std::false_type
{ };
template<typename... Types>
struct has_common_type<Types..., std::void_t<std::common_type<Types...>::type>> : std::true_type
{ };
This however does not work, because the template parameter pack must be the last parameter. The compiler raises the following error:
error: template parameter pack must be the last template parameter
template<typename... Types, typename Enable = void>
How can one go about defining such a template?