An iterator provides a container-oriented way to traverse elements without depending on numeric indexes. It can be compared with a container’s end iterator to determine whether a search succeeded. section 3.1 section 6.8
Mistake: favoring indexes over iterators. Indexing encourages array-shaped solutions, risks off-by-one errors, and excludes containers that cannot be indexed. Iterators keep traversal tied to the container interface. section 6.8
Search with an iterator
std::find returns an iterator. Compare it with values.end() to distinguish a found key from an exhausted search. Modern C++ can limit that iterator to the if statement: if (auto it = std::find(values.begin(), values.end(), key); it != values.end()). section 3.1














