Adobe Systems Incorporated


Categories: containers, functors Component type: type


The function object hash<T> is a HashFunction; it is used as the default hash function by all of the Hashed Associative Containers that are included in the STL.

The hash<T> template is only defined for template arguments of type char*, const char*, Rope, Rope, and the built-in integral types. [1] If you need a Hash Function with a different argument type, you must either provide your own template specialization or else use a different Hash Function.


int main()
  hash<const char*> H;
  cout << "foo -> " << H("foo") << endl;
  cout << "bar -> " << H("bar") << endl;


Defined in the headers hash_map and hash_set, and in the backward-compatibility headers hash_map.h and hash_set.h. This class is an SGI extension; it is not part of the C++ standard.

Template parameters

Parameter Description Default
T The argument type. That is, the type of object that is being hashed.  

Model of


Type requirements

T must be a type for which a specialization of hash has been defined. The STL defines the following specializations:

  • char*
  • const char*
  • Rope
  • Rope
  • char
  • signed char
  • unsigned char
  • short
  • unsigned short
  • int
  • unsigned int
  • long
  • unsigned long

Public base classes



Member Where defined Description
size_t operator()(const T& x) HashFunction Returns x's hash value.

New members

All of hash's members are defined in the HashFunction requirements. Hash does not introduce any new members.


[1] Technically, what this means is that the actual template hash<T> is an empty class; the member function operator() is defined only in the various specializations.

See also

HashedAssociativeContainer, HashFunction

Copyright © 2006-2007 Adobe Systems Incorporated.

Use of this website signifies your agreement to the Terms of Use and Online Privacy Policy.

Search powered by Google