Iterators for a range point to the first element and the element after the last

All algorithms take a pair of iterators, where the first one points to the first element in the range and the second one points to one element beyond the last element in the range. Take a look at the following code snippet:

auto vec=std::vector<std::string>{  "a","b","c","d","e","f"};auto first = vec.begin();auto last = vec.end(); 

As seen in the image, the last iterator now points to an imagined element after "f":

Get C++ High Performance 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.