fork download
  1. #include <cstdlib>
  2. #include <tuple>
  3. #include <unordered_map>
  4. #include <vector>
  5. #include <boost/functional/hash.hpp> /* hash_combine */
  6. template <typename T>
  7.  
  8. struct vectorHasher{
  9. std::size_t operator()(std::vector<T> const &in) const
  10. {
  11. using boost::hash_value;
  12. using boost::hash_combine;
  13. // Start with a hash value of 0
  14. std::size_t seed = 0;
  15. T value;
  16. for (int i=0; i< in.size(); i++)
  17. {
  18. value = static_cast<T>(in[i]);
  19. hash_combine(seed, hash_value(value));
  20. }
  21. return seed;
  22. }
  23. };
  24.  
  25.  
  26. int main()
  27. {
  28. typedef std::unordered_map< std::vector<std::size_t>, int, vectorHasher<std::size_t> > map_type;
  29. map_type mymap;
  30.  
  31. std::vector<size_t> vec (3,100);
  32. mymap[vec] = 1;
  33.  
  34. return 0;
  35. }
Success #stdin #stdout 0s 3468KB
stdin
Standard input is empty
stdout
Standard output is empty