Or login with:
#include <hash_map> namespace std{ template < class Key, class Type, class Traits=hash_compare<Key, less<Key> >, class Allocator=allocator<pair <const Key, Type> > > class hash_map; }
| Parameter | Description |
|---|---|
| Key | The element data type to be stored in the hash_map |
| Type | The element data type to be stored in the hash_map |
| Traits | The type which includes two function objects, one of class compare that is a binary predicate able to compare two element values as sort keys to determine their relative order and a hash function that is a unary predicate mapping key values of the elements to unsigned integers of type size_t. This argument is optional, and hash_compare<Key, less<Key> > is the default value |
| Allocator | The type that represents the stored allocator object that encapsulates details about the hash_map's allocation and de-allocation of memory.This argument is optional, and the default value is allocator<pair <const Key, Type>> |
// Create an empty hash_map h_map of key type integer hash_map <int, int> h_map; // Create an empty hash_map h_map1 with the key comparison function of less than hash_map <int, int, hash_compare <int, less<int> > > h_map1; // Create an empty hash_map h_map2 with the key comparison function of greater than hash_map <int, int, hash_compare <int, greater<int> > > h_map2; //
| Operator | Description |
|---|---|
| operator!= | Tests if the hash_map object on the left side of the operator is not equal to the hash_map object on the right side |
| operator< | Tests if the hash_map object on the left side of the operator is less than the hash_map object on the right side |
| operator<= | Tests if the hash_map object on the left side of the operator is less than or equal to the hash_map or object on the right side |
| operator== | Tests if the hash_map object on the left side of the operator is equal to the hash_map object on the right side |
| operator> | Tests if the hash_map object on the left side of the operator is greater than the hash_map object on the right side |
| operator>= | Tests if the hash_map object on the left side of the operator is greater than or equal to the hash_map object on the right side |
| operator[ ] | Inserts an element into a hash_map with a specified key value |
| Class | Description |
|---|---|
| hash_compare | Describes an object that can be used by any of the hash associative containers: hash_map, hash_multimap, hash_set, or hash_multiset, as a default Traits parameter object to order and hash the elements they contain |
| value_compare | Provides a function object that can compare the elements of a hash_map by comparing the values of their keys to determine their relative order in the hash_map |
| hash_map | Used for the storage and fast retrieval of data from a collection in which each element is a pair that has a sort key whose value is unique and an associated data value |
| Typedef | Description |
|---|---|
| allocator_type | A type that represents the allocator class for the hash_map object |
| const_iterator | A type that provides a bidirectional iterator that can read a const element in the hash_map |
| const_pointer | A type that provides a pointer to a const element in a hash_map |
| const_reference | A type that provides a reference to a const element stored in a hash_map for reading and performing const operations |
| const_reverse_iterator | A type that provides a bidirectional iterator that can read any const element in the hash_map |
| difference_type | A signed integer type that can be used to represent the number of elements of a hash_map in a range between elements pointed to by iterators |
| iterator | A type that provides a bidirectional iterator that can read or modify any element in a hash_map |
| key_compare | A type that provides a function object that can compare two sort keys to determine the relative order of two elements in the hash_map |
| key_type | A type describes the sort key object that constitutes each element of the hash_map |
| mapped_type | A type that represents the data type stored in a hash_map |
| pointer | A type that provides a pointer to an element in a hash_map |
| reference | A type that provides a reference to an element stored in a hash_map |
| reverse_iterator | A type that provides a bidirectional iterator that can read or modify an element in a reversed hash_map |
| size_type | An unsigned integer type that can represent the number of elements in a hash_map |
| value_type | A type that provides a function object that can compare two elements as sort keys to determine their relative order in the hash_map |
| Function | Description |
|---|---|
| begin() | Returns an iterator addressing the first element in the hash_map |
| rbegin() | Returns an iterator addressing the first element in a reversed hash_map |
| clear() | Erases all the elements of a hash_map |
| count() | Returns the number of elements in a hash_map whose key matches a parameter-specified key |
| empty() | Tests if a hash_map is empty |
| end() | Returns an iterator that addresses the location succeeding the last element in a hash_map |
| rend() | Returns an iterator that addresses the location succeeding the last element in a reversed hash_map |
| equal_range() | Returns a pair of iterators, respectively, to the first element in a hash_map with a key that is greater than a specified key and to the first element in the hash_map with a key that is equal to or greater than the key |
| erase() | Removes an element or a range of elements in a hash_map from specified positions |
| find() | Returns an iterator addressing the location of an element in a hash_map that has a key equivalent to a specified key |
| get_allocator() | Returns a copy of the allocator object used to construct the hash_map |
| hash_map() | Constructs a hash_map that is empty or that is a copy of all or part of some other hash_map |
| insert() | Inserts an element or a range of elements into a hash_map |
| key_comp() | Returns an iterator to the first element in a hash_map with a key value that is equal to or greater than that of a specified key |
| lower_bound() | Returns an iterator to the first element in a hash_map with a key value that is equal to or greater than that of a specified key |
| upper_bound() | Returns an iterator to the first element in a hash_map that with a key value that is greater than that of a specified key |
| size() | Specifies a new size for a hash_map |
| max_size() | Returns the maximum length of the hash_map |
| swap() | Exchanges the elements of two hash_maps |
| value_comp() | Retrieves a copy of the comparison object used to order element values in a hash_map |
#include <iostream> #include <hash_map> #define _DEFINE_DEPRECATED_HASH_CLASSES 0 typedef pair <int, int> Int_Pair; using namespace std; using namespace stdext; int main() { hash_map <int, int> hm1; hash_map <int, int> :: iterator hm1_Iter; hash_map <int, int> :: const_iterator hm1_cIter; hm1.insert (Int_Pair(0, 0)); hm1.insert (Int_Pair(1, 1)); hm1.insert (Int_Pair(2, 4)); hm1_cIter = hm1.begin ( ); cout <<"The first element of hm1 is "<<hm1_cIter -> first<<"."<<endl; hm1_Iter = hm1.begin ( ); hm1.erase ( hm1_Iter ); // The following 2 lines would err because the iterator is const // hm1_cIter = hm1.begin ( ); // hm1.erase ( hm1_cIter ); hm1_cIter = hm1.begin( ); cout <<"The first element of hm1 is now "<<hm1_cIter -> first<<"."<<endl; return 0; }
You must login to leave a messge