【发布时间】:2019-06-18 08:49:08
【问题描述】:
模板可以根据枚举值进行专门化
#include <type_traits>
template<typename T, typename = void>
struct Specialize
{
};
template<typename T>
struct Specialize<T, typename std::enable_if<std::is_enum<T>::value>::type>
{
void convert() { }
};
enum E
{
};
int main()
{
Specialize<E> spec;
spec.convert();
}
// My doubt: is below code valid? if not how to achieve this?
enum E
{
E1,
E2
};
int main()
{
Specialize<E, E1> spec;
spec.convert();
}
这是对以下问题的回答的后续问题。
How can I partially specialize a class template for ALL enums?
我已经复制粘贴了上面链接问题答案中的代码。
我的更改出现以下错误。
error: type/value mismatch at argument 2 in template parameter list for _template<class T, class>
【问题讨论】:
标签: c++ c++11 templates sfinae template-specialization