Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-60399

QMap::insertMulti / QMultiMap does not honour stability of insertion

    XMLWordPrintable

Details

    • Bug
    • Resolution: Unresolved
    • P2: Important
    • None
    • 5.9
    • None

    Description

      A multi-insert should add elements to the container in the order of which the elements are inserted.

      Instead, they're added in the opposite order (maybe it always goes for the leftmost node?). In other words, this code:

      #include <QtCore>
      
      int main(int argc, char *argv[])
      {
          QCoreApplication a(argc, argv);
      
          QMultiMap<int, int> map;
          map.insert(0, 0);
          map.insert(0, 1);
      
          for (auto &i : map)
              qDebug() << i;;
      }
      

      prints 1, 0.

      This means that adding a map to another map in iteration order would "reverse" its run of contiguous keys, making the two maps compare unidentical:

      #include <QtCore>
      
      int main(int argc, char *argv[])
      {
          QCoreApplication a(argc, argv);
      
          QMultiMap<int, int> map;
          map.insert(0, 0);
          map.insert(0, 1);
      
          QMultiMap<int, int> map2;
          for (auto i = map.constBegin(), e = map.constEnd(); i != e; ++i)
              map2.insert(i.key(), i.value());
      
          Q_ASSERT(map == map2);
      }
      

      Attachments

        Issue Links

          Activity

            People

              thiago Thiago Macieira
              peppe Giuseppe D'Angelo
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated: