Details
-
Suggestion
-
Resolution: Unresolved
-
P3: Somewhat important
-
None
-
None
-
None
-
8
-
Foundation PM Prioritized
Description
Q(Multi)Hash, unlike QMap containers, and unlike std::unordered_map, lacks the equal_range() function. Currently, the only option to find the range of equal elements in a QMultiHash is to loop over the successors of the result of find(), which is not very nice.
Acceptance criteria: The following test passes and has complexity linear in N = std::distance(b, e):
QMultiHash<int, QString> h = { {0, "zero"}, {1, "one"}, {1, "uno"}, {2, "two"}, }; auto r = h.equal_range(1); static_assert(std::is_same_v<decltype(r.first), QMultiHash<int, QString>::iterator>); static_assert(std::is_same_v<decltype(r.second), QMultiHash<int, QString>::iterator>); QCOMPARE_NE(r.first, h.end()); QCOMPARE_NE(r.second, h.end()); QCOMPARE_NEW(r.first, r.second); QCOMPARE_EQ(std::distance(r.first, r.second), 2); QCOMPARE_EQ(r.first.key(), 1); QCOMPARE_EQ(std::next(r.first).key(), 1); h.erase(r.first, r.second); // QTBUG-106175 QMultiHash<int, QString> res = {{0, "zero"), {2, "two"}}; QCOMPARE_EQ(h, res);
Attachments
Issue Links
- relates to
-
QTBUG-106175 Q(Multi)Hash is missing range-erase()
-
- Open
-
-
QTBUG-106180 QSet is missing range-erase()
-
- Open
-
-
QTBUG-106182 QString/QByteArray are missing (non-range-) erase()
-
- Closed
-