Assuming stdext :: hash_value provides a good hash distribution for each of the first and second, what you did is fine if you do not expect a disproportionate number of pairs of mirror images (e.g., (1,2) and (2, one)). If your data set is such that you expect a lot, you might consider setting up a hash function to make them different. For example, inverting the first hash value:
return ~stdext::hash_value<T>(rhs.first) ^ stdext::hash_value<T>(rhs.second);
I mention this only because you expressed concern about mirror image pairs. If your input is close to random in this regard, then ^ should be fine. Remember that the goal is to minimize collisions, and not to avoid them completely.
Mike woolf
source share