From 0d9934d4bcf56dc7711060edf5418e96138f4d94 Mon Sep 17 00:00:00 2001 From: Volker Hilsheimer Date: Thu, 15 Oct 2020 17:04:20 +0200 Subject: Consistenly deprecate QMultiMap insert, add moving unite overload Change-Id: I8d1d30f3962b0444c27591bf45b6b3c538172039 Reviewed-by: Giuseppe D'Angelo --- src/corelib/tools/qmap.h | 45 +++++++++++++++++++++++----------------- src/corelib/tools/qmultimap.qdoc | 14 ++++++++++++- 2 files changed, 39 insertions(+), 20 deletions(-) (limited to 'src/corelib') diff --git a/src/corelib/tools/qmap.h b/src/corelib/tools/qmap.h index f7915b149c..7292617904 100644 --- a/src/corelib/tools/qmap.h +++ b/src/corelib/tools/qmap.h @@ -1333,29 +1333,13 @@ public: { unite(map); } -#endif + QT_DEPRECATED_VERSION_X_6_0("Use unite() instead") void insert(QMultiMap &&map) { - if (!map.d || map.d->m.empty()) - return; - - if (map.d.isShared()) { - // fall back to a regular copy - insert(map); - return; - } - - detach(); - -#ifdef __cpp_lib_node_extract - map.d->m.merge(std::move(d->m)); -#else - map.d->m.insert(std::make_move_iterator(d->m.begin()), - std::make_move_iterator(d->m.end())); -#endif - *this = std::move(map); + unite(std::move(map)); } +#endif iterator replace(const Key &key, const T &value) { @@ -1408,6 +1392,29 @@ public: d->m = std::move(copy); return *this; } + + QMultiMap &unite(QMultiMap &&other) + { + if (!other.d || other.d->m.empty()) + return *this; + + if (other.d.isShared()) { + // fall back to a regular copy + unite(other); + return *this; + } + + detach(); + +#ifdef __cpp_lib_node_extract + other.d->m.merge(std::move(d->m)); +#else + other.d->m.insert(std::make_move_iterator(d->m.begin()), + std::make_move_iterator(d->m.end())); +#endif + *this = std::move(other); + return *this; + } }; Q_DECLARE_ASSOCIATIVE_ITERATOR(MultiMap) diff --git a/src/corelib/tools/qmultimap.qdoc b/src/corelib/tools/qmultimap.qdoc index 8b3337e59b..d07383a366 100644 --- a/src/corelib/tools/qmultimap.qdoc +++ b/src/corelib/tools/qmultimap.qdoc @@ -865,15 +865,17 @@ Inserts all the items in \a map into this map. */ -#endif /*! \fn template void QMultiMap::insert(QMultiMap &&map) \since 5.15 + \obsolete Use unite() instead. + \overload Moves all the items from \a map into this map. If \a map is shared, then the items will be copied instead. */ +#endif /*! \fn template QMultiMap::iterator QMultiMap::replace(const Key &key, const T &value) @@ -947,6 +949,16 @@ key multiple times. */ +/*! + \fn template QMultiMap &QMultiMap::unite(QMultiMap &&other) + + Moves all the items from the \a other map into this map. If a + key is common to both maps, the resulting map will contain the + key multiple times. + + If \a other is shared, then the items will be copied instead. +*/ + /*! \fn template QMultiMap operator+=(QMultiMap &lhs, const QMultiMap &rhs) Inserts all the items in the \a rhs map into the \a lhs map and -- cgit v1.2.3