Template specialization for enum
I'm not sure if I understand your question correctly, but you can instantiate the template on specific enums:
template <typename T>
void f(T value);
enum cars { ford, volvo, saab, subaru, toyota };
enum colors { red, black, green, blue };
template <>
void f<cars>(cars) { }
template <>
void f<colors>(colors) { }
int main() {
f(ford);
f(red);
}
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.