diff options
Diffstat (limited to 'src/corelib/tools/qmap.h')
-rw-r--r-- | src/corelib/tools/qmap.h | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/src/corelib/tools/qmap.h b/src/corelib/tools/qmap.h index afc4ca37c4..65b3ba55db 100644 --- a/src/corelib/tools/qmap.h +++ b/src/corelib/tools/qmap.h @@ -220,6 +220,8 @@ class QMap using MapData = QMapData<std::map<Key, T>>; QtPrivate::QExplicitlySharedDataPointerV2<MapData> d; + friend class QMultiMap<Key, T>; + public: using key_type = Key; using mapped_type = T; @@ -778,6 +780,35 @@ public: qSwap(d, other.d); } + explicit QMultiMap(const QMap<Key, T> &other) + : d(other.isEmpty() ? nullptr : new MapData) + { + if (d) { + Q_ASSERT(other.d); + d->m.insert(other.d->m.begin(), + other.d->m.end()); + } + } + + explicit QMultiMap(QMap<Key, T> &&other) + : d(other.isEmpty() ? nullptr : new MapData) + { + if (d) { + Q_ASSERT(other.d); + if (other.d.isShared()) { + d->m.insert(other.d->m.begin(), + other.d->m.end()); + } else { +#ifdef __cpp_lib_node_extract + d->m.merge(std::move(other.d->m)); +#else + d->m.insert(std::make_move_iterator(other.d->m.begin()), + std::make_move_iterator(other.d->m.end())); +#endif + } + } + } + explicit QMultiMap(const std::multimap<Key, T> &other) : d(other.empty() ? nullptr : new MapData(other)) { |