Boost logo

Boost :

From: Peter Dimov (pdimov_at_[hidden])
Date: 2005-03-10 17:51:19

> The idea is that you can alter only some part of the
> hashing scheme and benefit of the preexisting definitions: [...]

I think I see your point. You want something like this:

template<class F> size_t hash_value( int x, F const & )
    return x;

template<class F, class T> size_t hash_value( vector<T> const & v, F const &
f )
    return for_each( v.begin(), v.end(), f ).value();

which, when combined with a suitable combiner 'f':

class F

    // state


    template<class T> void operator()( T const & t )
        // combine state with hash_value( t, F() );

    size_t value() const
        // collapse state into a size_t and return it

will automatically propagate it downwards if one invokes hash_value on
vector<vector<vector<int> > >. Interesting, but overkill, IMO. ;-)

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