Boost logo

Boost :

From: Daniel James (daniel_at_[hidden])
Date: 2005-03-15 17:03:28


Peter Dimov wrote:
> Dave Harris wrote:
>
>>
>> But suppose I have pair< pair<int,int>, pair<int,int> > ? Shouldn't
>> that yield the same hash value as int[4] ?
>
>
> I don't expect a pair< pair<int, int>, pair<int, int> > to be frequently
> refactored into an int[4]. So no, I don't think that it should
> necessarily have the same hash value as an int[4]. Similarly, I don't
> think that vector< vector<int> > should necessarily have the same hash
> value as its flattened vector<int> counterpart.

They definitely should not for vector< vector<int> >. boost::hash should
reflect std::equal_to, and std::equal_to does not flatten sequences.

And since we're treating pairs like ranges of two values, nested pairs
should mirror nested vectors.

Of course, when using a custom equality function object which flattens
sequences, a custom hash function with this behaviour is correct.


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk