问题描述
有些东西(下面的无效代码):
模板< typename T>
void f(T value);
template<>
void f<枚举T(T值);
如果不可能,那么假设我有一些类型的专业化,如code> int , unsigned int
, long long
, unsigned long long
等,那么枚举值将使用哪个特殊化?
您可以使用,从< type_traits>
中完成此操作。
, litb发布了一个非常的详细和详细的说明,说明如何使用Boost等价物来完成。
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);
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?
You can use std::enable_if
with std::is_enum
from <type_traits>
to accomplish this.
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.
这篇关于枚举的模板专业化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!