diff options
author | Samuel Gaist <samuel.gaist@edeltech.ch> | 2016-11-29 11:06:24 +0100 |
---|---|---|
committer | Samuel Gaist <samuel.gaist@edeltech.ch> | 2017-05-05 14:25:56 +0000 |
commit | ae292be8690109940fdd9862321b2389a0957404 (patch) | |
tree | 594a2391a33ba8361efc914d3cf4c0a867d10a81 /src/corelib/tools/qhash.h | |
parent | c2c50268912bc49d104a8d04a54f2e9d5e35d6f8 (diff) |
Implement key-value iterator
This patch implements an iterator that returns a pair containing both the
key and the value of an entry in QHash/QMap.
[ChangeLog][QtCore][Containers] Added an stl-like iterator to go through
QHash/QMap returning both the key and the value of the element pointed to.
That lets QHash/QMap interoperate better with stl's algorithms like
std::set_union.
Change-Id: Idbf8a8581510b3493648c34ab04c556de9fa4aa7
Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
Diffstat (limited to 'src/corelib/tools/qhash.h')
-rw-r--r-- | src/corelib/tools/qhash.h | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/src/corelib/tools/qhash.h b/src/corelib/tools/qhash.h index c59f789cb2..bcaaec0ec6 100644 --- a/src/corelib/tools/qhash.h +++ b/src/corelib/tools/qhash.h @@ -447,6 +447,9 @@ public: const_iterator base() const { return i; } }; + typedef QKeyValueIterator<const Key&, const T&, const_iterator> const_key_value_iterator; + typedef QKeyValueIterator<const Key&, T&, iterator> key_value_iterator; + // STL style inline iterator begin() { detach(); return iterator(d->firstNode()); } inline const_iterator begin() const { return const_iterator(d->firstNode()); } @@ -458,6 +461,12 @@ public: inline const_iterator constEnd() const { return const_iterator(e); } inline key_iterator keyBegin() const { return key_iterator(begin()); } inline key_iterator keyEnd() const { return key_iterator(end()); } + inline key_value_iterator keyValueBegin() { return key_value_iterator(begin()); } + inline key_value_iterator keyValueEnd() { return key_value_iterator(end()); } + inline const_key_value_iterator keyValueBegin() const { return const_key_value_iterator(begin()); } + inline const_key_value_iterator constKeyValueBegin() const { return const_key_value_iterator(begin()); } + inline const_key_value_iterator keyValueEnd() const { return const_key_value_iterator(end()); } + inline const_key_value_iterator constKeyValueEnd() const { return const_key_value_iterator(end()); } QPair<iterator, iterator> equal_range(const Key &key); QPair<const_iterator, const_iterator> equal_range(const Key &key) const Q_DECL_NOTHROW; |