Martin Perry Martin Perry - 10 months ago 77
C++ Question

C++11 - typeid uniqueness

In C++11, I am using this


for my own hash computation. I don't need the result to be same between the program runs or compilations. I just need it to be unique for the types.
I know, that it can return same name for different types, but it is usually with const, pointers etc.
In my case,
is only
class XY
struct XX
or derived types.

In this case, can I assume, that
will be unique?

Answer Source

You should use std::type_index for mapping purposes.

The type_index class is a wrapper class around a std::type_info object, that can be used as index in associative and unordered associative containers. The relationship with type_info object is maintained through a pointer, therefore type_index is CopyConstructible and CopyAssignable.