Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Multimap containing pairs?

Is it possible for a multimap to contain within it pairs? IE, rather then being defined as multimap<char,int> for instance, it would be defined as multimap<pair, pair>?

How would this multimap then be sorted? Also, how would one access the individual contents of each pair?

like image 641
BSchlinker Avatar asked Dec 28 '22 13:12

BSchlinker


1 Answers

Is it possible for a multimap to contain within it pairs?

Yes its possible.

How would this multimap then be sorted?

By the key/first pair (ie, first by the first element of the first pair, then by the second element of the first pair).

Also, how would one access the individual contents of each pair?

multimap<pair <T1, T2>, pair<T3, T4> >::iterator it = mymultimap.begin();
it->first.first;
it->first.second;
it->second.first;
it->second.second;

In other words, a multimap of pairs works exactly as expected!

Update: Also, I'd like to add that I discourage any use of pairs of pairs, it makes the code very hard to read, use structs with real variable names instead.

like image 182
Viktor Sehr Avatar answered Dec 31 '22 01:12

Viktor Sehr