incubator-stdcxx-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Martin Sebor (JIRA)" <>
Subject [jira] Created: (STDCXX-216) std::map::insert (iterator, pair) doesn't use hint properly
Date Wed, 28 Jun 2006 18:01:33 GMT
std::map::insert (iterator, pair) doesn't use hint properly

         Key: STDCXX-216
     Project: C++ Standard Library
        Type: Bug

  Components: 23. Containers  
    Versions: 4.1.2, 4.1.3    
 Environment: all
    Reporter: Martin Sebor

Moved from the Rogue Wave bug tracking database:

****Created By: sebor @ Mar 23, 2004 04:17:39 PM****
Topic:Error in map::insert
map::insert( iterator, pair) does not work    (11/06/2003 02:13 AM)
I wanted to use the map::insert( iterator, pair) method to speed up things, but
my tests
showed that it was slower than the simple insert.
Debugging showed that the test for usability of the position iterator always fails:
iterator before = --position;
if (_key_compare( before.first, (key) v) && _key_compare( (key) v,
position.first)) ..

Reason: 'before' and 'position' are equal, and (more simple term)
a < b && b < a
is always false.

I guess it should read
iterator before = position;

I found the same problem in STL library with CPP Builder 5 as well as on Sun
Solaris 8,
Sun Workshop 6 update 1 C++ 5.2 Patch 109508-09.

Has anybody found this error too? Or, can anyone tell me in which version is it

Another point is: Accoring to the manual the iterator should point to the last
element smaller than the element to insert. If the code would be changed as
suggested above, it would work if the iterator pointed to the next-greater
element in the map ...
To make it work as described, the code would have to be
iterator after = position;
if (_key_compare( position.first, (key) v) && _key_compare( (key) v,
after.first)) ..

But I did not check the following insert methode if a pointer to the element
before or after the new one is required, so it may need even more code changes
or a change of the description...

Hth anybody else too, and maybe sbd can tell me in versions this problem is fixed?
Thx in advance!
Re: map::insert( iterator, pair) does not work    (11/17/2003 04:49 PM)
We are not aware of this problem. The use of the hint argument by insert() isn't clearly specified
in the C++ standard (in fact, there is an open issue on it -- see We'll look into it.


This message is automatically generated by JIRA.
If you think it was sent incorrectly contact one of the administrators:
For more information on JIRA, see:

View raw message