[Interest] Missing QMap Algebra?

MÃ¥rten Nordheim marten.nordheim at qt.io
Tue Mar 23 15:01:51 CET 2021


Hello!

QMap::insert(const QMap &) was added in 5.15. No operator+ though.

https://doc.qt.io/qt-5/qmap.html#insert-2

________________________________________
From: Interest <interest-bounces at qt-project.org> on behalf of Jason H <jhihn at gmx.com>
Sent: Tuesday, March 23, 2021 14:52
To: interestqt-project.org
Subject: [Interest] Missing QMap Algebra?

I've been in the python world lately and python has a dict.update() https://python-reference.readthedocs.io/en/latest/docs/dict/update.html
It seems that QMap has no such function anymore, but it also never did? unite() would make a QMultiMap, so there would be multiple entries rather than one. Which has me asking the question, do I have to provide this myself? Seems a pretty trivial thing to have to provide?

    QVariantMap map_a, map_b;
    ...
    auto combined_map = map_a;
    for (const QString& key: map_b.keys()) {
        combined_map[key] = map_b[key];
    }

Additionally there is no + operator for it, which is actually what I want:

    combined_map = map_a + map_b;

But I would be happy with:

   combined_map.update(map_b);


Additionally if we're trying to provide as much algebra as possible:

    map_a = combined_map - map_b.keys() // remove by matching key
    map_a = combined_map - map_b;       // remove by matching key-value pairs

In Python, these are doable in a 1-line list/dict comprehension.

Thoughts?

_______________________________________________
Interest mailing list
Interest at qt-project.org
https://lists.qt-project.org/listinfo/interest


More information about the Interest mailing list