how to use an unordered_set as a hash key - ordering-invariant hash and equal_to function

117 Views Asked by At

I am trying to use an unordered_set as a key to an unordered_map. I created std::hash which will iterate over the elements and combine hash of all the elements and std::equal_to which will iterate over the elements and do equality comparison.

But I am running into this issue: Is iteration order of two unordered_set-s with same contents guaranteed to be the same

Since the order of two sets with same contents is not guaranteed to be the same my hash and equal_to functions are incorrect.

Is there a way to make this work in C++23?

How to create ordering-invariant hash and equal_to function for unordered_set?

0

There are 0 best solutions below