反向或反向迭代 unordered_map [英] Reversing or reverse iterating an unordered_map

查看:88
本文介绍了反向或反向迭代 unordered_map的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图以相反的顺序打印 unordered_map 的内容,但是它没有 rbegin 或 rend,所以你不能使用 reverse_iterator.unordered_map 的反转应该如何完成?

I'm trying to print the contents of an unordered_map in reverse order, but it doesn't have rbegin or rend, so you can't use reverse_iterator. How is reversing of the unordered_map supposed to be done?

编辑(来自评论):我希望键按照它们插入的顺序排列,因此我不能使用 map.键似乎保留在插入顺序中,但我需要将它们反转.

EDIT (from comment): I want the keys to be in the order they were inserted in, hence I cant use map. The keys appear to stay in the insertion order, but I need them reversed.

推荐答案

只需阅读问题中的第一句话即可找到答案:

Just reading the first sentence in your question gives you the answer:

我正在尝试反向打印 unordered_map 的内容订购

I'm trying to print the contents of an unordered_map in reverse order

您不能按任何顺序打印,因为它是无序的.在无序结构中谈论秩序是没有意义的.unordered_map 的内容在内部如何组织并不重要:这是一个实现细节,您无法访问它.对于外界来说,unordered_map 完全没有顺序,你不能指望它这样做.

You cannot print in any order because, well, it is unordered. It makes no sense talking about order in an unordered structure. It does not matter how the contents of an unordered_map are organised internally: this is an implementation detail and you cannot access it. To the outside world, an unordered_map exhibits no order at all and you cannot expect it to do it.

这篇关于反向或反向迭代 unordered_map的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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