From b5af74a5f6061f626e7c81a51606c9ae42633813 Mon Sep 17 00:00:00 2001 From: Carlin St Pierre Date: Sun, 23 Apr 2017 13:58:56 +1000 Subject: [PATCH] Added toHash to Vector --- gl3n/linalg.d | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/gl3n/linalg.d b/gl3n/linalg.d index 450c82f..3b351c2 100644 --- a/gl3n/linalg.d +++ b/gl3n/linalg.d @@ -668,6 +668,20 @@ struct Vector(type, int dimension_) { else { assert(false); } } + size_t toHash() const nothrow @safe { + size_t h = 0; + foreach (v; vector) { + h = hashOf(v, h); + } + return h; + } + + unittest { + assert(__traits(compiles, string[vec2]), "Unable to construct an associative array with a Vector as the key"); + string[vec2] aa = [ vec2(1, 2): "test" ]; + assert(aa[vec2(1, 2)] == "test"); + } + } /// Calculates the product between two vectors.