In C++ is there a way to convert a type to an integer at compile-time (maybe with typeid) ? My goal is to pass a unique code for each type in that class :
template<int TypeCode>
class MyClass
{
};
EDIT : Some more details about what I am trying to do. In fact, MyClass will be more like that :
template<int Code>
class AbstractBase
{
};
I write a highly templated code with a lot of CRTP technique, and I need to check compatibilites between types for some operations. To do so, my idea was to inherit compatible types from the AbstractBase class specifying the same code for all these types. Using that, and simply calling std::enable_if<std::is_base_of<AbstractBase<MyCode>, T>::value>::typeI would be able to check for type compatibility for some operations.
At first order, I can generate a code by hand, but it would be more elegant, if I can generate this code from types automatically.
static_castif it's properly convertible.typeidis runtime.