I need to create a collection of key/value pairs like this:
map<const int, string[]> myMap; // psuedo code
What would be the best way of going about it?
Is there a way to do it where i can initialize it in one line like:
myMap.Insert(1, new string[]{ "stack", "is", "awesome" }); // pseudo code
Assuming you decide to stick with roughly the structure you’re currently using (with
intas the key and a collection ofstrings as the associated value) you probably want to usestd::vector<std::string>as the value, so yourmapis defined like:In this case, it’s probably easiest to use array-like notation to do your insertion:
As it stands, this depends on using a C++11 braced initializer list. That will work with the newest compilers (e.g., gcc 4.7.0) but fail on many that are older are not yet as close to conforming with C++11 (e.g., VC++10, VC++11 beta).