Boost logo

Boost :

From: Dave Harris (brangdon_at_[hidden])
Date: 2005-03-22 12:31:16

In-Reply-To: <d1on4o$ijr$1_at_[hidden]>
daniel_at_[hidden] (Daniel James) wrote (abridged):
> > Admittedly hash_combine is also (nearly) redundant, being definable
> > as:
> >
> > void hash_combine( size_t &hash, const T &t ) {
> > hash_range( hash, &t, &t+1 );
> > }
> >
> > if T does not overload address-of.

Note this is currently true because hash_range is defined as having the
effect of:

    void hash_range( size_t &hash, It first, It last ) {
        for (; first != last; ++first)
            hash_combine( hash, *first );

so calling hash_range on a range of 1 element returns the same result as
calling hash_combine with that element.

> Since nested vectors give different hash values to their flattened
> form, I don't think a single element vector should have the same hash
> values as it's element.

It doesn't. One is:

    return hash_value( t );

the other is:

    size_t hash = 0;
    hash_combine( hash, t );
    return hash;

All the proposed definitions of hash_combine make these different. There
is at least an xor, and possible a constant added.

-- Dave Harris, Nottingham, UK

Boost list run by bdawes at, gregod at, cpdaniel at, john at