Search code examples
c++multimap

C++: Storing groups of three in a multimap


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?


Solution

  • 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}.