I am wondering whether this is true? If it is, is this behavior guaranteed by the c++ standard?
views:
72answers:
1
+3
A:
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).
James McNellis
2010-07-28 03:16:12
Thanks. I mean multimap in my previous post.
Thomson Tan
2010-07-28 03:23:21
this statement seems different from the last proposed new standard that I have (but that is 21 months old (N2798=08-0308))I quote:For multiset and multimap, insert and erase preserve the relative ordering of equivalent elements. page 768If a range containing elements equivalent to t exists in a_eq, t is inserted at the end of that range.page 771
pgast
2010-07-28 04:30:24
@pgast: Very interesting. That language is in the C++0x FCD (N3092). However, it is not the case in the current C++ standard (C++03) that the relative ordering is maintained. Thanks for pointing out that change.
James McNellis
2010-07-28 12:43:54