Skip to content
This repository has been archived by the owner on Oct 12, 2022. It is now read-only.

Commit

Permalink
Merge pull request #2547 from n8sh/delegateHash
Browse files Browse the repository at this point in the history
 hashOf of delegate: allow CTFE when null plus don't need to use bytesHash
merged-on-behalf-of: Nicholas Wilson <[email protected]>
  • Loading branch information
dlang-bot authored Apr 6, 2019
2 parents 4f258a2 + 2c667f7 commit 4ad638f
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/core/internal/hash.d
Original file line number Diff line number Diff line change
Expand Up @@ -531,13 +531,16 @@ if (!is(T == enum) && (is(T == struct) || is(T == union))
mixin(_hashOfStruct);
}

//delegate hash. CTFE unsupported
//delegate hash. CTFE only if null.
@trusted @nogc nothrow pure
size_t hashOf(T)(scope const T val, size_t seed = 0) if (!is(T == enum) && is(T == delegate))
{
assert(!__ctfe, "unable to compute hash of "~T.stringof~" at compile time");
const(ubyte)[] bytes = (cast(const(ubyte)*)&val)[0 .. T.sizeof];
return bytesHashWithExactSizeAndAlignment!T(bytes, seed);
if (__ctfe)
{
if (val is null) return hashOf(size_t(0), hashOf(size_t(0), seed));
assert(0, "unable to compute hash of "~T.stringof~" at compile time");
}
return hashOf(val.ptr, hashOf(cast(void*) val.funcptr, seed));
}

//address-based class hash. CTFE only if null.
Expand Down

0 comments on commit 4ad638f

Please sign in to comment.