c++ - Initialize static const std::map during compile time? -


i have table in c++ program , have initialize @ beginning of program using this:

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

i wondering if there anyway can make initialization process happen @ compile time rather run time? understand has small impact of performance program. curious in scope of current c++11/14/17 semantic possible or not.

no, can't initialize std::map data in compile time!

however, can use "fancier" initializer if prefer, can have data in const std::map, in case trying do.

static const map<string, int> m = {     { "a", 1 },     { "b", 2 } }; 

but again, not initialize std::map in compile time. behind scenes, std::map job in runtime.


Comments

Popular posts from this blog

html - How to set bootstrap input responsive width? -

javascript - Highchart x and y axes data from json -

javascript - Get js console.log as python variable in QWebView pyqt -