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>
bb10
Marc Mutz 2022-01-28 00:48:59 +01:00
parent 1e07787142
commit f08f28548a
1 changed files with 2 additions and 12 deletions

View File

@ -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