From 11ec9bb3c2b0b0982a813f56288e5f6988ca1f25 Mon Sep 17 00:00:00 2001 From: xzyfer Date: Mon, 17 Nov 2014 16:00:24 +1100 Subject: [PATCH] Maps should support numbers as keys --- ast.hpp | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/ast.hpp b/ast.hpp index f6200eef9..5e4265e2b 100644 --- a/ast.hpp +++ b/ast.hpp @@ -980,10 +980,32 @@ namespace Sass { private: ADD_PROPERTY(Type, type); ADD_PROPERTY(string, value); + size_t hash_; public: Textual(string path, Position position, Type t, string val) - : Expression(path, position, true), type_(t), value_(val) + : Expression(path, position, true), type_(t), value_(val), + hash_(0) { } + + virtual bool operator==(Expression& rhs) const + { + try + { + Textual& e = dynamic_cast(rhs); + return e && value() == e.value() && type() == e.type(); + } + catch (std::bad_cast&) + { + return false; + } + } + + virtual size_t hash() + { + if (hash_ == 0) hash_ = std::hash()(value_) ^ std::hash()(type_); + return hash_; + } + ATTACH_OPERATIONS(); };