| Erases the element pointed to by | ||
size_type erase(const key_type& k) | Associative Container | Erases the element whose key is |
void erase(iterator first, iterator last) | Associative Container | Erases all elements in a range. |
void clear() | Associative Container | Erases all of the elements. |
iterator find(const key_type& k) const | Associative Container | Finds an element whose key is |
size_type count(const key_type& k) const | Unique Associative Container | Counts the number of elements whose key is |
pair<iterator, iterator> equal_range(const key_type& k) const | Associative Container | Finds a range containing all elements whose key is |
bool operator==(const hash_set&, const hash_set&) | Hashed Associative Container | Tests two hash_sets for equality. This is a global function, not a member function. |
All of
[1] This member function relies on
Associative Container, Hashed Associative Container, Simple Associative Container, Unique Hashed Associative Container,
hash_map<Key, Data, HashFcn, EqualKey, Alloc>
Category: containers
Component type: type
Looking up an element in a
struct eqstr {
bool operator()(const char* s1, const char* s2) const {
return strcmp(s1, s2) == 0;
}
};
int main() {
hash_map<const char*, int, hash<const char*>, eqstr> months;
months['january'] = 31;
months['february'] = 28;
months['march'] = 31;
months['april'] = 30;
months['may'] = 31;
months['june'] = 30;
months['july'] = 31;
months['august'] = 31;
months['september'] = 30;
months['october'] = 31;
months['november'] = 30;
months['december'] = 31;
cout << 'september –> ' << months['september'] << endl;
cout << 'april –> ' << months['april'] << endl;
cout << 'june –> ' << months['june'] << endl;
cout << 'november –> ' << months['november'] << endl;
