summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMarc Mutz <marc.mutz@qt.io>2022-01-28 00:48:59 +0100
committerMarc Mutz <marc.mutz@qt.io>2022-01-29 02:40:12 +0100
commitf08f28548ae04f89bd7fd24673c1369c96786e3d (patch)
treeebecc96075d8da0f59f419e50042c6fa29dae5fa /src
parent1e07787142284dcf3d67463187367d92f05f6246 (diff)
QFlatMap: implement mutable op[] via try_emplace()
De-duplicates code. Pick-to: 6.3 Change-Id: Id7841a0717cd66bd56d489e6d2630e9eeb284316 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io> Reviewed-by: Jörg Bornemann <joerg.bornemann@qt.io>
Diffstat (limited to 'src')
-rw-r--r--src/corelib/tools/qflatmap_p.h14
1 files changed, 2 insertions, 12 deletions
diff --git a/src/corelib/tools/qflatmap_p.h b/src/corelib/tools/qflatmap_p.h
index 3be517a483..d9bcf08c9d 100644
--- a/src/corelib/tools/qflatmap_p.h
+++ b/src/corelib/tools/qflatmap_p.h
@@ -651,22 +651,12 @@ public:
T &operator[](const Key &key)
{
- auto it = lower_bound(key);
- if (it == end() || key_compare::operator()(key, it.key())) {
- c.keys.insert(toKeysIterator(it), key);
- return *c.values.insert(toValuesIterator(it), T());
- }
- return it.value();
+ return try_emplace(key).first.value();
}
T &operator[](Key &&key)
{
- auto it = lower_bound(key);
- if (it == end() || key_compare::operator()(key, it.key())) {
- c.keys.insert(toKeysIterator(it), key);
- return *c.values.insert(toValuesIterator(it), T());
- }
- return it.value();
+ return try_emplace(std::move(key)).first.value();
}
T operator[](const Key &key) const