summaryrefslogtreecommitdiff
path: root/core/templates/hash_map.h
diff options
context:
space:
mode:
Diffstat (limited to 'core/templates/hash_map.h')
-rw-r--r--core/templates/hash_map.h56
1 files changed, 30 insertions, 26 deletions
diff --git a/core/templates/hash_map.h b/core/templates/hash_map.h
index 55292d3eb5..e5f73171a2 100644
--- a/core/templates/hash_map.h
+++ b/core/templates/hash_map.h
@@ -373,76 +373,80 @@ public:
/** Iterator API **/
- struct Iterator {
- _FORCE_INLINE_ KeyValue<TKey, TValue> &operator*() const {
+ struct ConstIterator {
+ _FORCE_INLINE_ const KeyValue<TKey, TValue> &operator*() const {
return E->data;
}
- _FORCE_INLINE_ KeyValue<TKey, TValue> *operator->() const { return &E->data; }
- _FORCE_INLINE_ Iterator &operator++() {
+ _FORCE_INLINE_ const KeyValue<TKey, TValue> *operator->() const { return &E->data; }
+ _FORCE_INLINE_ ConstIterator &operator++() {
if (E) {
E = E->next;
}
return *this;
}
- _FORCE_INLINE_ Iterator &operator--() {
+ _FORCE_INLINE_ ConstIterator &operator--() {
if (E) {
E = E->prev;
}
return *this;
}
- _FORCE_INLINE_ bool operator==(const Iterator &b) const { return E == b.E; }
- _FORCE_INLINE_ bool operator!=(const Iterator &b) const { return E != b.E; }
+ _FORCE_INLINE_ bool operator==(const ConstIterator &b) const { return E == b.E; }
+ _FORCE_INLINE_ bool operator!=(const ConstIterator &b) const { return E != b.E; }
- _FORCE_INLINE_ operator bool() const {
+ _FORCE_INLINE_ explicit operator bool() const {
return E != nullptr;
}
- _FORCE_INLINE_ Iterator(HashMapElement<TKey, TValue> *p_E) { E = p_E; }
- _FORCE_INLINE_ Iterator() {}
- _FORCE_INLINE_ Iterator(const Iterator &p_it) { E = p_it.E; }
- _FORCE_INLINE_ void operator=(const Iterator &p_it) {
+ _FORCE_INLINE_ ConstIterator(const HashMapElement<TKey, TValue> *p_E) { E = p_E; }
+ _FORCE_INLINE_ ConstIterator() {}
+ _FORCE_INLINE_ ConstIterator(const ConstIterator &p_it) { E = p_it.E; }
+ _FORCE_INLINE_ void operator=(const ConstIterator &p_it) {
E = p_it.E;
}
private:
- HashMapElement<TKey, TValue> *E = nullptr;
+ const HashMapElement<TKey, TValue> *E = nullptr;
};
- struct ConstIterator {
- _FORCE_INLINE_ const KeyValue<TKey, TValue> &operator*() const {
+ struct Iterator {
+ _FORCE_INLINE_ KeyValue<TKey, TValue> &operator*() const {
return E->data;
}
- _FORCE_INLINE_ const KeyValue<TKey, TValue> *operator->() const { return &E->data; }
- _FORCE_INLINE_ ConstIterator &operator++() {
+ _FORCE_INLINE_ KeyValue<TKey, TValue> *operator->() const { return &E->data; }
+ _FORCE_INLINE_ Iterator &operator++() {
if (E) {
E = E->next;
}
return *this;
}
- _FORCE_INLINE_ ConstIterator &operator--() {
+ _FORCE_INLINE_ Iterator &operator--() {
if (E) {
E = E->prev;
}
return *this;
}
- _FORCE_INLINE_ bool operator==(const ConstIterator &b) const { return E == b.E; }
- _FORCE_INLINE_ bool operator!=(const ConstIterator &b) const { return E != b.E; }
+ _FORCE_INLINE_ bool operator==(const Iterator &b) const { return E == b.E; }
+ _FORCE_INLINE_ bool operator!=(const Iterator &b) const { return E != b.E; }
- _FORCE_INLINE_ operator bool() const {
+ _FORCE_INLINE_ explicit operator bool() const {
return E != nullptr;
}
- _FORCE_INLINE_ ConstIterator(const HashMapElement<TKey, TValue> *p_E) { E = p_E; }
- _FORCE_INLINE_ ConstIterator() {}
- _FORCE_INLINE_ ConstIterator(const ConstIterator &p_it) { E = p_it.E; }
- _FORCE_INLINE_ void operator=(const ConstIterator &p_it) {
+ _FORCE_INLINE_ Iterator(HashMapElement<TKey, TValue> *p_E) { E = p_E; }
+ _FORCE_INLINE_ Iterator() {}
+ _FORCE_INLINE_ Iterator(const Iterator &p_it) { E = p_it.E; }
+ _FORCE_INLINE_ void operator=(const Iterator &p_it) {
E = p_it.E;
}
+ operator ConstIterator() const {
+ return ConstIterator(E);
+ }
+
private:
- const HashMapElement<TKey, TValue> *E = nullptr;
+ HashMapElement<TKey, TValue> *E = nullptr;
};
_FORCE_INLINE_ Iterator begin() {