I am initializing map<string, vector<string> > as follows:
map <string, vector<string> > dict;
dict["USA"].push_back("NYC");
dict["USA"].push_back("LA");
dict["USA"].push_back("Chicago");
dict["USA"].push_back("Dallas");
dict["India"].push_back("Delhi");
dict["India"].push_back("Bombay");
dict["Australia"].push_back("Melbourne");
dict["Australia"].push_back("Sydney");
dict["Australia"].push_back("Adelaide");
I find this cumbersome. The same thing can be done in tcl as follows which is cleaner:
array set dict {
USA {NYC LA Chicago Dallas}
India {Delhi Bombay}
Australia {Melbourne Sydney Adelaide}
}
Is there a more cleaner way to initialize in C++? My compiler is gcc 3.4.6
If you’re not afraid of using a bit of C-style macros and some helper constructs you might find this slightly less irritable; the initialization of the map is done in one line; you only need to fill in the data (which you must do anyway).