You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am aware of this design: "no const Key in std::pair<Key, Value>". I did not care until today.
For a map, this is fine; I mean, willing to change the key is not common. But for a set, the situation is more bug-prone.
For example, this does not compile and this is good:
std::unordered_set<int> set0({ 1, 2, 3 });
for (auto& x : set)
x++; // "can't change x"
While the following is compiling fine, hence there is a risk of introducing a subtle bug for a common for-loop scenario.
ankerl::unordered_dense::set<int> set({ 1, 2, 3 });
for (auto& x : set)
x++;
Hence I am wondering: what is the reason for not being able to have a const key? No way to change that, at least for a set?
The text was updated successfully, but these errors were encountered:
Good point, for unordered_dense::set iterator and const_iterator could be the same type. I'll see what I can do here.
I can't internally use const types though because the map/set has to move elements around. Whenever you delete one entry, the map/set will move an element into the empty place.
I am aware of this design: "no const Key in std::pair<Key, Value>". I did not care until today.
For a map, this is fine; I mean, willing to change the key is not common. But for a set, the situation is more bug-prone.
For example, this does not compile and this is good:
While the following is compiling fine, hence there is a risk of introducing a subtle bug for a common for-loop scenario.
Hence I am wondering: what is the reason for not being able to have a const key? No way to change that, at least for a set?
The text was updated successfully, but these errors were encountered: