I wonder whether some template meta-programming facility allows one to assign unique integral identifiers for different types, i.e. something like this:
class Type;
enum { id = identifier<Type>() /* or identifier<Type>::id, ... */ };
static_assert(id == identifier<Type>(), "...");
The hard part, I think, is that the identifier should remain the same across a single compilation (which is not necessarily the same thing as a compilation unit). But of course, as I don’t know the technique or if it’s possible at all, I really don’t know what’s the hardest part.
Edit: How about within a single compilation unit?
Take a look into Modern C++ Design by Andrei Alescandrescu. He analyses this problem quite deeply, template meta-programming heavily involved, in one of the chapters about abstract factories. The conclusion is that there is no absolutely portable way how to map a C++ type to integral type.