枚举模板专业化 [英] Template specialization for enum

查看:95
本文介绍了枚举模板专业化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以为枚举专门化模板化方法?

Is it possible to specialize a templatized method for enums?

类似(下面无效的代码):

Something like (the invalid code below):

template <typename T>
void f(T value);

template <>
void f<enum T>(T value);

在这种情况下是不可能的,那么假设我有一些类型的专业化, c $ c> int , unsigned int long long unsigned long long 等,那么枚举值将使用哪些特殊化?

In the case it's not possible, then supposing I have specializations for a number of types, like int, unsigned int, long long, unsigned long long, etc, then which of the specializations an enum value will use?

推荐答案

您可以使用 std :: enable_if std :: is_enum

In an answer to one of my questions, litb posted a very detailed and well-written explanation of how this can be done with the Boost equivalents.

这篇关于枚举模板专业化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆