Module 11 · Iterators: The Thing Between a Container and an Algorithm
Every Iterator Operation, One by One, With Its Cost
Free with an accountReading
Bob keeps the club's waiting list in a std::list and wants the fourth name. He writes auto it = l.begin() + 3;, as he would on a vector, and GCC 12 answers with one error and a page of notes. Which operations does each iterator have, and what does each one cost? This lesson takes them one at a time.
Checking what this lesson needs for you…
What is inside Every Iterator Operation, One by One, With Its Cost
- begin and end, and std::begin, std::end and std::size
- cbegin and cend, and begin() on a const container
- rbegin, rend and base()
- * and ->
- ++it and it++
- --it, and the forward_list that refuses it
- Jumps: + n, - n, +=, [n], it2 - it1 and <
- std::advance, std::next and std::prev
- std::distance
- back_inserter: copying into a container that grows
- front_inserter and inserter
- istream_iterator: every number until the input ends
- The parentheses trapIntermediate
- ostream_iterator, and the separator after the last value
- When an iterator stops being validIntermediate
- iterator_traits and the five tags in codeIntermediate
- Every cost in one table