From dbb54805f63f9ed68d84fe090d608872f16170d2 Mon Sep 17 00:00:00 2001 From: Lars Knoll Date: Thu, 22 Nov 2018 12:00:53 +0100 Subject: Deprecate reverse iteration on QHash MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 Reviewed-by: Lars Knoll --- src/corelib/serialization/qdatastream.h | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'src/corelib/serialization/qdatastream.h') 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 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; -- cgit v1.2.3