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 ?

11th Oct 2022, 4:53 PM
Ketan Lalcheta
Ketan Lalcheta - avatar
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
26th Oct 2022, 6:01 AM
Bob_Li
Bob_Li - avatar
0
for simplicity? doing a == is simpler than two <
25th Oct 2022, 10:45 AM
Bob_Li
Bob_Li - avatar
0
Than same goes with set also... there also simplicity important
26th Oct 2022, 4:36 AM
Ketan Lalcheta
Ketan Lalcheta - avatar