问题
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?
回答1:
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.
来源:https://stackoverflow.com/questions/3099947/multimap-containing-pairs