public member function
size_type count (const key_type& k) const;
Count elements with a specific key
Searches the container for elements with a key equivalent to k and returns the number of matches.
Because all elements in a map container are unique, the function can only return 1 (if the element is found) or zero (otherwise).
Two keys are considered equivalent if the container's comparison object returns false reflexively (i.e., no matter the order in which the keys are passed as arguments).
- Key to search for.
Member type key_type is the type of the element keys in the container, defined in map as an alias of its first template parameter (Key).
1 if the container contains an element whose key is equivalent to k, or zero otherwise.
Member type size_type is an unsigned integral type.
int main ()
for (c='a'; c<'h'; c++)
std::cout << c;
std::cout << " is an element of mymap.\n";
std::cout << " is not an element of mymap.\n";
a is an element of mymap.
b is not an element of mymap.
c is an element of mymap.
d is not an element of mymap.
e is not an element of mymap.
f is an element of mymap.
g is not an element of mymap.
Logarithmic in size.
The container is accessed.
No mapped values are accessed: concurrently accessing or modifying elements is safe.
Strong guarantee: if an exception is thrown, there are no changes in the container.
- Get iterator to element (public member function
- Return container size (public member function
- Get range of equal elements (public member function