diff --git a/std/typecons.d b/std/typecons.d index 1f1afaa9896..382eeeb00e0 100644 --- a/std/typecons.d +++ b/std/typecons.d @@ -1169,12 +1169,12 @@ if (distinctFieldNames!(Specs)) Returns: A `size_t` representing the hash of this `Tuple`. */ - size_t toHash() const nothrow @safe + size_t toHash() const nothrow @trusted { size_t h = 0; static foreach (i, T; Types) {{ - const k = typeid(T).getHash((() @trusted => cast(const void*) &field[i])()); + const k = hashOf(field[i]); static if (i == 0) h = k; else @@ -1474,6 +1474,19 @@ if (distinctFieldNames!(Specs)) assert(t == AliasSeq!(1, Bad(1), "asdf")); } +// Ensure Tuple.toHash works +@safe unittest +{ + Tuple!(int, int) point; + assert(point.toHash == typeof(point).init.toHash); + assert(tuple(1, 2) != point); + assert(tuple(1, 2) == tuple(1, 2)); + point[0] = 1; + assert(tuple(1, 2) != point); + point[1] = 2; + assert(tuple(1, 2) == point); +} + /** Creates a copy of a $(LREF Tuple) with its fields in _reverse order.