00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #ifndef __TUPLE_HASH_HH
00018 # define __TUPLE_HASH_HH
00019
00020 # include <tuple>
00021 # include "mhash.hh"
00022
00023 namespace aurelia {
00024 template <typename T, size_t N = 0>
00025 struct get_hash {
00026 };
00027
00028 template <typename... T, size_t N>
00029 struct get_hash<std::tuple<T...>, N> {
00030 static void make(size_t& hash, const std::tuple<T...>& t) {
00031 get_hash<std::tuple<T...>, N-1>::make(hash, t);
00032 hash = (hash << 11) | (hash >> 21);
00033 hash ^= mhash<typename std::tuple_element<N, std::tuple<T...> >::type>()
00034 (std::get<N>(t));
00035 }
00036 };
00037
00038 template <typename... T>
00039 struct get_hash<std::tuple<T...>, 0u> {
00040 static void make(size_t& hash, const std::tuple<T...>& t) {
00041 hash = mhash<typename std::tuple_element<0, std::tuple<T...> >::type>()
00042 (std::get<0>(t));
00043 }
00044 };
00045
00046 }
00047
00048 namespace std {
00049 template <typename... T>
00050 struct hash<tuple<T...> >: public unary_function<tuple<T...>, size_t> {
00051 size_t operator()(const tuple<T...>& t) const {
00052 size_t hash = 0;
00053 aurelia::get_hash<tuple<T...>, tuple_size<tuple<T...> >::value-1>::make(hash, t);
00054 return hash;
00055 }
00056 };
00057
00058 template <>
00059 struct hash<tuple<> >: public unary_function<tuple<>, size_t> {
00060 size_t operator()(const tuple<>& ) const {
00061 return 0;
00062 }
00063 };
00064 }
00065
00066 #endif