summaryrefslogtreecommitdiffstats
path: root/src/corelib/tools/qflatmap_p.h
diff options
context:
space:
mode:
authorMarc Mutz <marc.mutz@qt.io>2022-01-10 11:36:23 +0100
committerMarc Mutz <marc.mutz@qt.io>2022-01-12 16:14:18 +0100
commitb17c4d0e2e188c8e41afbccbc3ff4a96ec872e05 (patch)
tree009768316f0a493651af446740ccd2a490ef4791 /src/corelib/tools/qflatmap_p.h
parent6891e10f9717a51b72583bf18e5a1a8d5f5fd527 (diff)
QFlatMap: re-implement insert() via insert_or_assign()
Avoids code duplication. Pick-to: 6.3 6.2 Change-Id: Ic69e46108baf97a0dc9215866d6c707136ee40b2 Reviewed-by: Joerg Bornemann <joerg.bornemann@qt.io>
Diffstat (limited to 'src/corelib/tools/qflatmap_p.h')
-rw-r--r--src/corelib/tools/qflatmap_p.h37
1 files changed, 4 insertions, 33 deletions
diff --git a/src/corelib/tools/qflatmap_p.h b/src/corelib/tools/qflatmap_p.h
index fd08676ae3..4c35e0c3ae 100644
--- a/src/corelib/tools/qflatmap_p.h
+++ b/src/corelib/tools/qflatmap_p.h
@@ -679,51 +679,22 @@ public:
std::pair<iterator, bool> insert(const Key &key, const T &value)
{
- auto it = lower_bound(key);
- if (it == end() || key_compare::operator()(key, it.key())) {
- c.values.insert(toValuesIterator(it), value);
- auto k = c.keys.insert(toKeysIterator(it), key);
- return { fromKeysIterator(k), true };
- } else {
- it.value() = value;
- return {it, false};
- }
+ return insert_or_assign(key, value);
}
std::pair<iterator, bool> insert(Key &&key, const T &value)
{
- auto it = lower_bound(key);
- if (it == end() || key_compare::operator()(key, it.key())) {
- c.values.insert(toValuesIterator(it), value);
- return { fromKeysIterator(c.keys.insert(toKeysIterator(it), std::move(key))), true };
- } else {
- *toValuesIterator(it) = value;
- return {it, false};
- }
+ return insert_or_assign(std::move(key), value);
}
std::pair<iterator, bool> insert(const Key &key, T &&value)
{
- auto it = lower_bound(key);
- if (it == end() || key_compare::operator()(key, it.key())) {
- c.values.insert(toValuesIterator(it), std::move(value));
- return { fromKeysIterator(c.keys.insert(toKeysIterator(it), key)), true };
- } else {
- *toValuesIterator(it) = std::move(value);
- return {it, false};
- }
+ return insert_or_assign(key, std::move(value));
}
std::pair<iterator, bool> insert(Key &&key, T &&value)
{
- auto it = lower_bound(key);
- if (it == end() || key_compare::operator()(key, it.key())) {
- c.values.insert(toValuesIterator(it), std::move(value));
- return { fromKeysIterator(c.keys.insert(toKeysIterator(it), std::move(key))), true };
- } else {
- *toValuesIterator(it) = std::move(value);
- return {it, false};
- }
+ return insert_or_assign(std::move(key), std::move(value));
}
template <typename...Args>