11.3.5. Accessing Elements
The associative containers provide various ways to find a given element, which are described in Table 11.7 (p. 438). Which operation to use depends on what problem we are trying to solve. If all we care about is whether a particular element is in the container, it is probably best to use find
. For the containers that can hold only unique keys, it probably doesn’t matter whether we use find
or count
. However, for the containers with multiple keys, count
has to do more work: If the element is present, it still has to count how many elements have the same key. If we don’t need the count, it’s best to use find
:
Exercise 11.24: ...
Get C++ Primer, Fifth Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.