I have many classes, B1 B2 ... derived from the same class named A.
I want to create a function
getId<B1>() , getId<B2>() , ...
that return unique int for each class and have result that consistent with
get_id(new B1()) , get_id(new B2()) ....
In other words,
getId<Bi>() == get_id(new Bi()) .... for every i (1)
getId<Bi>() != getId<Bj>() .... when i!=j (2)
The B1 B2 is just a notation, they are longer names without integer in real life.
How to implements both functions?
Requirements :
1. I don't have to edit all Bi.h (B1 B2 ... class), because there are a lot of them.
2. Assignment integer for each class manually is not allowed, because it is tedious.
3. typeid or dynamic_cast can't be used, because it is slow (I tried.)
4. template is ok
5. non deterministic is ok
6. (bonus) If the generated integer is low-value (Ex. B1=1, B2=2 ...) , it would be nice.
The result (integer) will be used for a hash function.
I have searched, but not find any solution that meet both (1)&(2).
For example, Efficient way to generate id unique to class? is not helpful enough.