diff options
author | Marc Mutz <marc.mutz@kdab.com> | 2019-07-08 21:25:55 +0200 |
---|---|---|
committer | Marc Mutz <marc.mutz@kdab.com> | 2020-03-05 13:24:32 +0100 |
commit | bd84e8d63e6fc2e05df21e8c60d56c01b5fa0674 (patch) | |
tree | 84180408cd0c2ec394c973264f97c8cc809e044a /src/corelib/tools/qmap.h | |
parent | dfaca09e85a49d2983bb89893bfbe1ba4c19eab4 (diff) |
QHash/QMap: don't return const from value(), key()
... it breaks move semantics.
We can change these, since they're templates and a short survey shows
that no-one in Qt was crazy enough to inherit an exported class from
QHash or QMap.
Otherwise this would be BiC on MSVC, which encodes the return type.
There's also no safety benefit here, as none of the overloads returns
by reference, so users cannot expect map.value(key).mutate() to have
an effect on the element in the container.
In this, key() and value() differ from op[], which also returns const,
but whose overload returns a reference. op[] is therefore not proposed
here.
[ChangeLog][QtCore][QHash/QMultiHash/QMap/QMultiMap] The value() and
key() member functions now return T (was: const T), enabling move
semantics on their return values.
Change-Id: I0e5f53f9834caad458e3bde27f1daacbb4bac71b
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
Diffstat (limited to 'src/corelib/tools/qmap.h')
-rw-r--r-- | src/corelib/tools/qmap.h | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/src/corelib/tools/qmap.h b/src/corelib/tools/qmap.h index 6081019294..be8ba6c4ba 100644 --- a/src/corelib/tools/qmap.h +++ b/src/corelib/tools/qmap.h @@ -364,8 +364,8 @@ public: T take(const Key &key); bool contains(const Key &key) const; - const Key key(const T &value, const Key &defaultKey = Key()) const; - const T value(const Key &key, const T &defaultValue = T()) const; + Key key(const T &value, const Key &defaultKey = Key()) const; + T value(const Key &key, const T &defaultValue = T()) const; T &operator[](const Key &key); const T operator[](const Key &key) const; @@ -630,7 +630,7 @@ QT_WARNING_PUSH QT_WARNING_DISABLE_CLANG("-Wreturn-stack-address") template <class Key, class T> -Q_INLINE_TEMPLATE const T QMap<Key, T>::value(const Key &akey, const T &adefaultValue) const +Q_INLINE_TEMPLATE T QMap<Key, T>::value(const Key &akey, const T &adefaultValue) const { Node *n = d->findNode(akey); return n ? n->value : adefaultValue; @@ -979,7 +979,7 @@ Q_OUTOFLINE_TEMPLATE QList<Key> QMap<Key, T>::keys(const T &avalue) const } template <class Key, class T> -Q_OUTOFLINE_TEMPLATE const Key QMap<Key, T>::key(const T &avalue, const Key &defaultKey) const +Q_OUTOFLINE_TEMPLATE Key QMap<Key, T>::key(const T &avalue, const Key &defaultKey) const { const_iterator i = begin(); while (i != end()) { |