I need to find out whether a type is a template or not. To do this, I thought I would use two function overloads, like so:
template <typename T> // If T is a simple type this overload will be selected
consteval bool isTemplate(int) {
return false;
}
template <template <class...> class T> // This overload will be selected if T is a template and fits in as a template template parameter
consteval bool isTemplate(char) { // Dummy char parameter to avoid redefinition
return true;
}
However this doesn't work when T is a template with non-type template parameters, eg:
template <int N>
struct T {};
auto x = isTemplate<T>(0); // Error, second overload does not work
How do I make the second overload accept any template ? ( Or any alternative solution to detect whether a type is a template is welcome :)
Aucun commentaire:
Enregistrer un commentaire