满足条件的多种类型的模板类专业化
如果我有一个模板类,如下所示:
template<typename T>
class Type { /* ... */ };
在不以任何方式修改 Type
的情况下,是否有一种简单的方法可以将其专门用于匹配编译时条件的所有此类类型?例如,如果我想专门针对所有整型类型,我想做这样的事情(只有有效的事情,即):
template<typename T>
class Type<std::enable_if<std::is_integral<T>, T>::type> { /* ... */ };
If I have a template class, like so:
template<typename T>
class Type { /* ... */ };
Without modifying Type
in any way, is there a simple way to specialize it for all such types that match a compile-time condition? For example, if I wanted to specialize Type
for all integral types, I'd like to do something like this (only something that works, that is):
template<typename T>
class Type<std::enable_if<std::is_integral<T>, T>::type> { /* ... */ };
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这应该有效:
This should work: