diff options
author | Marc Mutz <marc.mutz@qt.io> | 2022-01-28 00:54:32 +0100 |
---|---|---|
committer | Marc Mutz <marc.mutz@qt.io> | 2022-01-30 04:14:21 +0100 |
commit | 64bc6509c350c5750c6432a0ae6876f4bfb97cd0 (patch) | |
tree | d5cb3504df081cc935ce84a3880a73c4bc826ceb /src/corelib/tools/qflatmap_p.h | |
parent | d336fdd393a8a97fbcb00837763b45602d346d34 (diff) |
QFlatMap: add full is_transparent support [3/3]: add overloads
Now add the missing overloads for mixed-type lookups, supported by
is_transparent Compare objects.
Pick-to: 6.3
Change-Id: Ib588b6a4f733d5d9908c8c7d7c209df6e7bd6674
Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Reviewed-by: Jörg Bornemann <joerg.bornemann@qt.io>
Diffstat (limited to 'src/corelib/tools/qflatmap_p.h')
-rw-r--r-- | src/corelib/tools/qflatmap_p.h | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/src/corelib/tools/qflatmap_p.h b/src/corelib/tools/qflatmap_p.h index 7e8b230fee..e066a53661 100644 --- a/src/corelib/tools/qflatmap_p.h +++ b/src/corelib/tools/qflatmap_p.h @@ -610,6 +610,12 @@ public: return do_remove(binary_find(key)); } + template <class X, class Y = Compare, is_marked_transparent<Y> = nullptr> + bool remove(const X &key) + { + return do_remove(binary_find(key)); + } + iterator erase(iterator it) { c.values.erase(toValuesIterator(it)); @@ -621,23 +627,49 @@ public: return do_take(binary_find(key)); } + template <class X, class Y = Compare, is_marked_transparent<Y> = nullptr> + T take(const X &key) + { + return do_take(binary_find(key)); + } + bool contains(const Key &key) const { return binary_find(key) != end(); } + template <class X, class Y = Compare, is_marked_transparent<Y> = nullptr> + bool contains(const X &key) const + { + return binary_find(key) != end(); + } + T value(const Key &key, const T &defaultValue) const { auto it = binary_find(key); return it == end() ? defaultValue : it.value(); } + template <class X, class Y = Compare, is_marked_transparent<Y> = nullptr> + T value(const X &key, const T &defaultValue) const + { + auto it = binary_find(key); + return it == end() ? defaultValue : it.value(); + } + T value(const Key &key) const { auto it = binary_find(key); return it == end() ? T() : it.value(); } + template <class X, class Y = Compare, is_marked_transparent<Y> = nullptr> + T value(const X &key) const + { + auto it = binary_find(key); + return it == end() ? T() : it.value(); + } + T &operator[](const Key &key) { return try_emplace(key).first.value(); @@ -793,11 +825,23 @@ public: return binary_find(k); } + template <class X, class Y = Compare, is_marked_transparent<Y> = nullptr> + iterator find(const X &key) + { + return binary_find(key); + } + const_iterator find(const key_type &k) const { return binary_find(k); } + template <class X, class Y = Compare, is_marked_transparent<Y> = nullptr> + const_iterator find(const X &key) const + { + return binary_find(key); + } + key_compare key_comp() const noexcept { return static_cast<key_compare>(*this); @@ -912,6 +956,12 @@ private: return { &c, std::as_const(*this).binary_find(key).i }; } + template <class X, class Y = Compare, is_marked_transparent<Y> = nullptr> + iterator binary_find(const X &key) + { + return { &c, std::as_const(*this).binary_find(key).i }; + } + const_iterator binary_find(const Key &key) const { auto it = lower_bound(key); @@ -923,6 +973,18 @@ private: return it; } + template <class X, class Y = Compare, is_marked_transparent<Y> = nullptr> + const_iterator binary_find(const X &key) const + { + auto it = lower_bound(key); + if (it != end()) { + if (!key_compare::operator()(key, it.key())) + return it; + it = end(); + } + return it; + } + void ensureOrderedUnique() { std::vector<size_type> p(size_t(c.keys.size())); |