如果2个元素的键相等,则std :: multimap是否保留插入顺序? [英] Will std::multimap preserve the insert order if the key of 2 elements equal to each other?

查看:288
本文介绍了如果2个元素的键相等,则std :: multimap是否保留插入顺序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道这是否属实? cd:std中的元素:

I am wondering whether this is true? If it is, is this behavior guaranteed by the c++ standard?

推荐答案

:map 必须有唯一的键,所以... no。

The elements in a std::map must have unique keys, so... no.

std :: multimap 容器允许多个值映射到一个键。当对 std :: multimap 进行迭代时,元素按键排序,但未指定具有相同键的元素的顺序。

The std::multimap container allows multiple values mapped to one key. When iterating over a std::multimap the elements are ordered by key, but the order of elements having the same key is not specified.

请注意,在即将到来的C ++ 0x标准(N3092)的最新草案中,具有相同键的元素的相对排序是有保证的(因此,将能够依靠这种行为)。

Note that in the latest draft of the forthcoming C++0x standard (N3092), the relative ordering of elements with the same key is guaranteed (so, at some point, you'll be able to rely on this behavior).

这篇关于如果2个元素的键相等,则std :: multimap是否保留插入顺序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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