问题描述
我需要确定一个类型是否是模板。为此,我想我会使用两个函数重载,如下所示:
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;
}
然而,当 T 是带有非类型模板参数的模板时,这不起作用,例如:
template <int N>
struct T {};
auto x = istemplate<T>(0); // Error,second overload does not work
如何让第二个重载接受任何模板? (或者任何检测类型是否为模板的替代解决方案都是受欢迎的:)
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)