Skip to content

Commit 3f42ed9

Browse files
committed
Fix unordered_map operator[] insertion behavior
1 parent 013de1f commit 3f42ed9

1 file changed

Lines changed: 4 additions & 8 deletions

File tree

include/webcc/core/unordered_map.h

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ namespace webcc
146146
return m_data[insertion_idx].value;
147147
}
148148

149-
// Basic iterator support
149+
// Basic iterator support - iterates over keys for clean "for key in map" syntax
150150
struct iterator {
151151
Entry* ptr;
152152
Entry* end;
@@ -160,13 +160,9 @@ namespace webcc
160160

161161
bool operator!=(const iterator& other) const { return ptr != other.ptr; }
162162

163-
struct Pair {
164-
Key& first;
165-
T& second;
166-
};
167-
168-
Pair operator*() { return {ptr->key, ptr->value}; }
169-
Pair* operator->() { return (Pair*)ptr; } // Hacky, but works for simple usage
163+
// Return key directly for "for key in map" syntax
164+
const Key& operator*() const { return ptr->key; }
165+
const Key* operator->() const { return &ptr->key; }
170166
};
171167

172168
iterator begin() {

0 commit comments

Comments
 (0)