Is it possible to specialize a templatized method for enums?
Something like (the invalid code below):
template
void f(T value);
t
Presumably, the only interesting thing you could do with a type that they only thing you know about it is that it's an enum, is cast it to its underlying type and operate on that. Here's how that might look like, using James' suggested approach (AKA SFINAE):
void Bar(int b); // and/or other underlying types
template
typename std::enable_if::value, void>::type
Foo(T enm)
{
Bar(static_cast::type>(enm));
}
As a related bonus, here's a similar method that would only get resolved for a specific type of your choosing (replace bool in is_same
to the type of your choosing):
template
typename std::enable_if::value, void>::type
Baz(T bl)
{
if (bl)
{
//...
}
else
{
//...
}
}