View source code Display the source code in object.d from which this page was generated on github. Improve this page Quickly fork, edit online, and submit a pull request for this page. Requires a signed-in GitHub account. This works well for small changes. If you'd like to make larger changes you may want to consider using local clone. Page wiki View or edit the community-maintained wiki page associated with this page.

Function object.hashOf

Calculates the hash value of arg with seed initial value. Result may be non-equals with typeid(T).getHash(&arg) The seed value may be used for hash chaining:

struct Test
{
    int a;
    string b;
    MyObject c;

    size_t toHash() const @safe pure nothrow
    {
        size_t hash = a.hashOf();
        hash = b.hashOf(hash);
        size_t h1 = c.myMegaHash();
        hash = h1.hashOf(hash); //Mix two hash values
        return hash;
    }
}

Prototype

size_t hashOf(T)(
  T arg,
  size_t seed = 0
);

Authors

Walter Bright, Sean Kelly

License

Boost License 1.0.

Comments