mardi 25 juillet 2017

Initialize static const std::map during compile time?

I have a look up table in my C++ program and for now I have to initialize it at the beginning of the program using something like this:

static const map<string, int> m;
m["a"] = 1;
m["b"] = 2;
...

I am just wondering if there is anyway I can make this initialization process happen at compile time rather than run time? I understand this has very small impact of performance to my program. I am just curious that with in the scope of current C++11/14/17 semantic it is possible or not.

Aucun commentaire:

Enregistrer un commentaire