包含对的多图? [英] Multimap containing pairs?

查看:175
本文介绍了包含对的多图?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

多重映射可以在其中包含对吗? IE,而不是定义为 multimap< char,int> 例如,它将被定义为 multimap< pair,pair >?



这个multimap如何排序?

解决方案

多重映射可以包含



通过键/第一对(即,首先由第一对的第一个元素,然后由第一对的第二个元素)排序。



此外,如何访问每个对的各个内容?

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

换句话说,多对对象完全符合预期!



更新:
另外,我想补充一点,我不鼓励使用成对的对,这使得代码很难阅读,使用structs真实变量名。


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.

这篇关于包含对的多图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆