I want to generate a hash for a class based on its derived type at compile time. Today I generate it like:
template<class Type>
class TypeBase
{
public:
static const unsigned s_kID;
};
template<class Type>
const unsigned TypeBase<Type>::s_kID = hash(typeid(Type));
but this generates (pretty unnecessarily) run time initialization code (the hash(..) function does a simple hash based on std::type_info::name() )
Ideas ?
Given everything else that happens at process startup, and how simple and elegant your existing code is, assuming you don't hash a gazillion types, I'd leave your existing solution exactly as it is.
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