包含对的多重映射?

发布于 2024-09-06 20:23:58 字数 186 浏览 2 评论 0 原文

多重映射是否可以包含在其对中? IE,而不是被定义为 multimap 例如,它会被定义为 multimap>?

那么这个多重映射将如何排序呢?另外,如何访问每一对的单独内容?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

断爱 2024-09-13 20:23:58

多重映射是否可以包含在其对中?

是的,这是可能的。

然后如何对这个多重映射进行排序?

按键/第一对(即,首先按第一对的第一个元素,然后按第一对的第二个元素)。

此外,如何访问每一对的单独内容?

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

换句话说,对的多重映射完全按照预期工作!

更新:
另外,我想补充一点,我不鼓励使用成对的任何对,它使代码很难阅读,而是使用具有真实变量名称的结构。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文