Will std::multimap preserve the insert order if the key of 2 elements equal to each other?
I am wondering whether this is true? If it is, is this behavior guaran开发者_如何学Pythonteed by the c++ standard?
The elements in a std::map
must have unique keys, so... no.
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.
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).
精彩评论