Std::hash specialisation for Identifier / unordered_map


#1

Wouldn’t it be nice there is a std::hash specialisation for the juce-type Identifier, so it can be used as a key in std::unordered_map?

My naive implementation

namespace std {
	template <> struct hash<Identifier>
	{
		size_t operator()(const Identifier &x) const
		{
			// works, but slow
			return x.toString().hash();
			
			// wouldn't it be faster, to use the char-pointer which should be unique per Identifier-String???
			//return somemagic_cast<size_t>(x.getCharPointer());
		}
	};
}

#2

The pointer is not a good idea (because it can change), instead the hash could be precalculated in the pooled String Array. Then we have a ultra fast solution.