1

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?

Mat
  • 202,337
  • 40
  • 393
  • 406

3 Answers3

2
std::map<std::string, int> isThisWhatYouNeed; //?
std::map<std::vector<std::string>, std::vector<int> > orThis; //?
user703016
  • 37,307
  • 8
  • 87
  • 112
2

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.

Stuart Golodetz
  • 20,238
  • 4
  • 51
  • 80
0

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 :)

CNeo
  • 736
  • 1
  • 6
  • 10