I need to create a map of vectors. The first vector contains a list of strings and the second vector contains a list of integer IDs. Is this possible?
-
1http://stackoverflow.com/questions/1380585/map-of-vectors-in-stl I think might be helpful – AMadmanTriumphs Dec 31 '11 at 12:34
3 Answers
std::map<std::string, int> isThisWhatYouNeed; //?
std::map<std::vector<std::string>, std::vector<int> > orThis; //?

- 37,307
- 8
- 87
- 112
You might want to look at Boost Variant (see http://www.boost.org). Then use:
std::map<std::string, boost::variant<std::vector<string>, std::vector<int>>>
If, on the other hand, you're trying to map from one vector to another, then you can do that by providing a custom sorting predicate for vectors of the key type when you construct the map.

- 20,238
- 4
- 51
- 80
If I understand your question correctly, you want a map of key=>vector, where one vector contains strings and the other ints?
You can't mix types like that. The closest you can do is create a map of key=>CustomClass where your custom class contains a vector of strings and a vector of ints, and both are populated.
Alternatively, if you want to be very clever and potentially create a massive debugging headache for you, you could do a map to void*, and manually manage what each pointer points to :)

- 736
- 1
- 6
- 10