문제

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top