Some may have noticed that std::hash does not support tuples. So I added an overload which just seems "nicer" than the solution I saw up till now. Anyone got ideas to further cut down this code? Please note that this is a compiler killer! The only one that could compile it was "Clang 3.2"... Intel Compiler 13.1 does not get the specialization and keeps telling "C++ standard does not support hash blabla". And we don't need to talk about the original Microsoft compiler do we.
BTW, my solution supports recursive tuples like std::tuple<std::tuple<int,int>,int>
so I am not sure if this also applies to the existing solutions I saw this day.
namespace std
{
template<typename... TTypes>
class hash<std::tuple<TTypes...>>
{
private:
typedef std::tuple<TTypes...> Tuple;
template<int N>
size_t operator()(Tuple value) const { return 0; }
template<int N, typename THead, typename... TTail>
size_t operator()(Tuple value) const
{
constexpr int Index = N - sizeof...(TTail) - 1;
return hash<THead>()(std::get<Index>(value)) ^ operator()<N, TTail...>(value);
}
public:
size_t operator()(Tuple value) const
{
return operator()<sizeof...(TTypes), TTypes...>(value);
}
};
}