suizokukan
suizokukan

Reputation: 1369

calling the (default) hash function for a vector

I'm trying to get the hash of different types of objects, like strings and vectors.

The following code is ok...

  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 by the 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 ?

Upvotes: 2

Views: 972

Answers (1)

Andy
Andy

Reputation: 30418

It looks like your compiler doesn't implement std::hash for std::vector.

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

Upvotes: 5

Related Questions