LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
HashTuple.h
Go to the documentation of this file.
1 // From https://stackoverflow.com/questions/7110301/generic-hash-for-tuples-in-unordered-map-unordered-set
2 // Maybe we should put something like this in a standard header?
3 namespace std {
4  namespace {
5  template <class T>
6  inline void hash_combine(std::size_t& seed, const T& v)
7  {
8  seed ^= std::hash<T>()(v) + 0x9e3779b9 + (seed << 6) + (seed >> 2);
9  }
10 
11  // Recursive template code derived from Matthieu M.
13  struct HashValueImpl {
14  static void apply(size_t& seed, const Tuple& tuple)
15  {
16  HashValueImpl<Tuple, Index - 1>::apply(seed, tuple);
17  hash_combine(seed, std::get<Index>(tuple));
18  }
19  };
20 
21  template <class Tuple>
22  struct HashValueImpl<Tuple, 0> {
23  static void apply(size_t& seed, const Tuple& tuple)
24  {
25  hash_combine(seed, std::get<0>(tuple));
26  }
27  };
28  }
29 
30  template <class... TT>
31  struct hash<std::tuple<TT...>> {
32  size_t operator()(const std::tuple<TT...>& tt) const
33  {
34  size_t seed = 0;
35  HashValueImpl<std::tuple<TT...>>::apply(seed, tt);
36  return seed;
37  }
38  };
39 }
size_t operator()(const std::tuple< TT... > &tt) const
Definition: HashTuple.h:32
STL namespace.
void * Tuple
Definition: DBFolder.h:13
Definition: type_traits.h:61
long seed
Definition: chem4.cc:67
double value
Definition: spectrum.C:18