Вопрос

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?

Это было полезно?

Решение

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

Другие советы

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;
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top