0
Why == is needed for unordered set
Hi all If we need to use custom class as key for map, we need to have overloaded < operator.... Reason is that set keeps internal data sorted. This sounds good. Now, question is about equality of two elements of set. If A<B and B<A is not true, we can say A==B where A and B both are class objects... this way we dont need == operator for set Now, lets talk about unordered set... as this works on hashing, we need to identify that at which index data should go...so we need to provide hashing function for our class.... now question is need of == operator... why it is needed ? Cant we manipulate from hashing function ?
3 Answers
+ 1
but you don't need to overload '<'. only '=='., unless you need ordering.
https://stackoverflow.com/questions/17016175/c-unordered-map-using-a-custom-class-type-as-the-key
0
for simplicity?
doing a == is simpler than two <
0
Than same goes with set also... there also simplicity important