[Interest] Missing QMap Algebra?

Jason H jhihn at gmx.com
Tue Mar 23 14:52:52 CET 2021


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?



More information about the Interest mailing list