mardi 28 juin 2016

Compile time replacement of string constants with integers

I have a list of pre-defined mappings of string constants to numbers outside of my code base. The integers map to data inside of the program but I want to use the far more readable string constants in my code. The resulting binary should only contain the numbers and not contain the string constants at all. Is it possible to replace the string constants with the mapped integer at compile time?

What I want to achieve is basically having this code:

getData("a string constant here");

and I want to transform it into this:

getData(277562452);

Is this possible via macros or constexpr?

Aucun commentaire:

Enregistrer un commentaire