2

I was wondering how you implement a multimap with groups of three values. For instance: [{a,b,c}, {d,e,f}]

Do you have to use std::pair?

Julia
  • 151
  • 3
  • 11

2 Answers2

3

Yes. Using std::pair is a reasonable way to represent the values {b,c} and {e,f} You would store each one in the multimap with key a, value {b,c} and key D, value {e,f}.

Then later you might have key a, value {z,y}. When that is inserted, you can then find key a, and it will return a iterator that you can fetch all of the values associated with key a.

If you do have tuples, then you might consider using key a, with the tuple {a,b,c}.

EvilTeach
  • 28,120
  • 21
  • 85
  • 141
  • There are many examples on this site and elsewhere. Consider http://stackoverflow.com/questions/247818/stlmultimap-how-do-i-get-groups-of-data?rq=1 Look to the right on this page, under the Related stuff. There are lots of good links that show you things about multimaps – EvilTeach Oct 19 '13 at 17:20
1

If you mean the key that represents itself a group of three values then for example you can use std::array as the key.

For example

std::multimap<std::array<int, 3>, std::string> m;
Vlad from Moscow
  • 301,070
  • 26
  • 186
  • 335