Uploaded image for project: 'C++ Standard Library'
  1. C++ Standard Library
  2. STDCXX-216

std::map::insert (iterator, pair) doesn't use hint properly

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 4.1.2, 4.1.3, 4.1.4
    • Fix Version/s: 4.2.1
    • Component/s: 23. Containers
    • Labels:
      None
    • Environment:

      all

      Description

      Moved from the Rogue Wave bug tracking database:

      ***Created By: sebor @ Mar 23, 2004 04:17:39 PM***
      http://www.roguewave.com/developer/forum/OpenForumThread.cfm?forum=100&thread=542
      ----------------------------------------------------------------------
      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;
      --before;

      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
      fixed?

      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;
      ++after;
      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!
      René

      ----------------------------------------------------------------------
      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
      http://anubis.dkuug.dk/jtc1/sc22/wg21/docs/lwg-active.html#233). We'll look into it.

      Thanks
      Martin

        Attachments

          Activity

            People

            • Assignee:
              vitek Travis Vitek
              Reporter:
              sebor Martin Sebor

              Dates

              • Created:
                Updated:
                Resolved:

                Time Tracking

                Estimated:
                Original Estimate - 8h Original Estimate - 8h
                8h
                Remaining:
                Remaining Estimate - 0h
                0h
                Logged:
                Time Spent - 9h
                9h

                  Issue deployment