C++ Compile time consistent identifier generation

Viewed 157

I need to implement a type index structure that would correctly and consistently identify every type in the project.

The issue with using something like std::type_index is that it needs to be consistent across different compilation units. I need it to be consistent between compilation units as I would be loading shared libraries as sub modules at runtime (thus they would not be linked to the main module) and they should all have the same indexes for the same types, and if I use std::type_index or a custom index generating function each compilation unit would have it's own implementation of index generation and thus the index can be inconsistent.

Is there any template way to generate unique indexes for types that is consistent across compilation units (ex. TypeA would have index 1 on first compile and the 2nd)?

Is there maybe any tool that would allow me to feed the source code into and consistently generate hard-coded indexes from that?

0 Answers
Related