Call (default) a hash function for a vector

I am trying to get a hash of various types of objects like strings and vectors.

The following code is fine ...

  std::string data = std::string("abc");
  std::cout << std::hash<std::string>()(data) << std::endl;

... but not this one, although I just replaced the string type with a vector type.

  std::vector<int> data( {1,2,3} );
  std::cout << std::hash<std::vector<int> >()(data) << std::endl;

g ++ -std = gnu + 11 says:

  invalid use of incomplete type 'struct std::hash<std::vector<int> >'

... why?

+2
source share
1 answer

It seems your compiler does not implement std::hashfor std::vector.

According to MSDN , Visual Studio only implements this for scalar types and some string types. According to cpluplus.com , compilers should only do this for simple types, not for all types.

+4
source

Source: https://habr.com/ru/post/1541974/


All Articles