Template Parameters

Both hash_map and hash_multimap have the following template parameters and defaults:

Listing: Hashmap Template Parameters
template <class Key, class T, class Hash = hash<Key>,
class Compare = std::equal_to<Key>,

class Allocator = std::allocator<std::pair<const Key, T> > >

class hash_(multi)map;

The first parameter is the type of key the map is to contain. It can be almost any type, but must be copyable.

The second parameter is the type of value that will be associated with each key. It can be almost any type, but must be copyable.

The third parameter is the hash function used to look up elements. It defaults to the hash function in <hash_fun>. Client code can use hash<Key> as is, specialize it, or supply completely different hash function objects or hash function pointers. The hash function must accept a Key, and return a size_t.

The fourth parameter is the comparison function which defaults to std::equal_to<Key>. This function should have equality semantics. A specific requirement is that if two keys compare equal according to Compare, then they must also produce the same result when processed by Hash.

The fifth and final parameter is the allocator, which defaults to std::allocator<std::pair<const Key, T> >. The same comments and requirements that appear in the standard for allocators apply here as well.