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?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With