Say I have some class template:
template<typename T>
class {
// ....
}
I can partially specialize this template for ALL pointers by:
template<typename T>
class<T *> {
// ....
}
Can I somehow specialize the template for ALL enums? i.e., do something like: (this doesn't work, though)
template<typename T>
class<enum T> {
// ....
}
use C++11 and SFINAE.
#include <type_traits>
template<typename T, typename = void>
struct Specialize
{
};
template<typename T>
struct Specialize<T, typename std::enable_if<std::is_enum<T>::value>::type>
{
void convert() { }
};
enum E
{
};
int main()
{
Specialize<E> spec;
spec.convert();
}
Without C++11 use boost::enable_if
and boost::is_enum
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With