summaryrefslogtreecommitdiffstats
path: root/src/corelib/serialization
diff options
context:
space:
mode:
authorLars Knoll <lars.knoll@qt.io>2018-11-22 12:00:53 +0100
committerMårten Nordheim <marten.nordheim@qt.io>2019-11-05 17:32:22 +0100
commitdbb54805f63f9ed68d84fe090d608872f16170d2 (patch)
treeb144940788fd969477ad29f6307a265c9aa121a0 /src/corelib/serialization
parent6f8a97e480f0b1db0b3d59d74dcf6a19963de7b8 (diff)
Deprecate reverse iteration on QHash
std::unordered_map only supports forward iteration for good reasons. Align our API with this by deprecating reverse iteration and the operator+/-() for iterators. [ChangeLog][QtCore][QHash] Reverse iteration over QHash is now deprecated. [ChangeLog][Potentially Binary-Incompatible Changes] QHash's iterator category was changed from bidirectional iterator to forward iterator. This may cause trouble if a library uses the iterator category to alter functionality through tag dispatching. This only applies when compiling the library or application with QT_DISABLE_DEPRECATED_BEFORE=0x050F00 and the other with a lower value. Change-Id: I0fb6d017cabdef1bc508e62f76dc2fa73cd3652d Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io> Reviewed-by: Lars Knoll <lars.knoll@qt.io>
Diffstat (limited to 'src/corelib/serialization')
-rw-r--r--src/corelib/serialization/qdatastream.h17
1 files changed, 17 insertions, 0 deletions
diff --git a/src/corelib/serialization/qdatastream.h b/src/corelib/serialization/qdatastream.h
index cfcd89333b..332828b21e 100644
--- a/src/corelib/serialization/qdatastream.h
+++ b/src/corelib/serialization/qdatastream.h
@@ -321,14 +321,31 @@ template <typename Container>
QDataStream &writeAssociativeContainer(QDataStream &s, const Container &c)
{
s << quint32(c.size());
+#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
// Deserialization should occur in the reverse order.
// Otherwise, value() will return the least recently inserted
// value instead of the most recently inserted one.
auto it = c.constEnd();
auto begin = c.constBegin();
while (it != begin) {
+ QT_WARNING_PUSH
+ QT_WARNING_DISABLE_DEPRECATED
--it;
+ QT_WARNING_POP
s << it.key() << it.value();
+#else
+ auto it = c.constBegin();
+ auto end = c.constEnd();
+ while (it != end) {
+ const auto rangeStart = it++;
+ while (it != end && rangeStart.key() == it.key())
+ ++it;
+ const qint64 last = std::distance(rangeStart, it) - 1;
+ for (qint64 i = last; i >= 0; --i) {
+ auto next = std::next(rangeStart, i);
+ s << next.key() << next.value();
+ }
+#endif
}
return s;