473,406 Members | 2,273 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Is std::multimap "stable" ?

Hello.

[lib.associative.reqmts] 9 says:

'' The fundamental property of iterators of associative containers is
that they iterate through the containers in the non-descending order of
keys where non-descending is defined by the comparison that was used to
construct them. ''

Does it mean that if I insert values into a multimap with equal keys, I
am guaranteed to receive them back with find() and equal_range() in the
same order I inserted them?

Thanks,
melfar

Apr 17 '06 #1
1 3777
In article <11*********************@t31g2000cwb.googlegroups. com>,
"me****@gmail.com" <me****@gmail.com> wrote:
Hello.

[lib.associative.reqmts] 9 says:

'' The fundamental property of iterators of associative containers is
that they iterate through the containers in the non-descending order of
keys where non-descending is defined by the comparison that was used to
construct them. ''

Does it mean that if I insert values into a multimap with equal keys, I
am guaranteed to receive them back with find() and equal_range() in the
same order I inserted them?

Thanks,
melfar


No, not according to the standard. However there are several issues of
interest.

First, see:

http://www.open-std.org/jtc1/sc22/wg...ctive.html#371

This LWG issue is in the working draft for C++0X (voted in just two
weeks ago). It states that once your equal keys are in the multimap,
they won't change order as the multimap rebalances due to further
inserts and erases. But it doesn't guarantee that the keys are placed
in any particular order related to the order in which they were inserted.

However, also see:

http://www.open-std.org/jtc1/sc22/wg...ctive.html#233

and a related paper:

http://www.open-std.org/jtc1/sc22/wg...005/n1780.html

If N1780 is accepted as the proposed resolution to 233, then your equal
keys will be in the order you inserted them, or as otherwise directed by
the optional "hint" parameter. That still doesn't mean that find()
would find the keys in that order, but it does mean that equal_range,
lower/upper_bound would find them in the expected order.

N1780 is still controversial on the committee, but does have support.
N1780 also points out that all existing implementations currently
interpret "insert without hint" as "insert at upper bound" (equal keys
will be in the order you inserted them). So there is also a second
answer to your original question:

Yes, all implementations will keep your inserted equal keys in the order
you inserted them. Use lower_bound or equal_range, not find, to find
them in that order.

Sorry the answer is so complicated.

-Howard
Apr 17 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

205
by: Jeremy Siek | last post by:
CALL FOR PAPERS/PARTICIPATION C++, Boost, and the Future of C++ Libraries Workshop at OOPSLA October 24-28, 2004 Vancouver, British Columbia, Canada http://tinyurl.com/4n5pf Submissions
235
by: napi | last post by:
I think you would agree with me that a C compiler that directly produces Java Byte Code to be run on any JVM is something that is missing to software programmers so far. With such a tool one could...
4
by: salem.ganzhorn | last post by:
#include <map> #include <iostream> using namespace std; int main( int argc, const char * argv ) {
48
by: Tony | last post by:
How much bloat does the STL produce? Is it a good design wrt code bloat? Do implementations vary much? Tony
22
by: nospam_news | last post by:
I currently get asked about my usage of "auto". What is it for? The keyword is clearly superflous here. In contrast to the huge majority of C/C++ developers I write definitions very explicitly...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.