View source code
Display the source code in object.d from which this page was generated on github.
Report a bug
If you spot a problem with this page, click here to create a Bugzilla issue.
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.

Function object.hashOf

Calculates the hash value of arg with an optional seed initial value. The result might not be equal to typeid(T).getHash(&arg).

size_t hashOf(T) (
  auto ref T arg,
  size_t seed
);

size_t hashOf(T) (
  auto ref T arg
);

Parameters

NameDescription
arg argument to calculate the hash value of
seed optional seed value (may be used for hash chaining)

Return

calculated hash value of arg

Example

class MyObject
{
    size_t myMegaHash() const @safe pure nothrow
    {
        return 42;
    }
}
struct Test
{
    int a;
    string b;
    MyObject c;
    size_t toHash() const 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;
    }
}

Authors

Walter Bright, Sean Kelly

License

Boost License 1.0.