What are Iterators?

What are Iterators?

- Iterators are the glue that hold the container and algorithms together. They provide an abstract view of data so that the writer of algorithm need not be concerned with concrete details of a myriad of data structures.
- At the same time, the standard model of data access provided by iterators relieves the containers from having to provide a more extensive set of access operations.
- An iterator is simply an abstract of the notion of a pointer to an element of a sequence.
- The key concepts of iterator are :

i. The element currently pointed to.
ii. Point to next element.
iii. Equality.

- The iterator classes and functions are declared in namespace std and found in <iterator>.
- The iterator is not a general pointer. Hence there is no concept of ‘null iterator’. The test is to determine whether an iterator points to an element or not is done by comparing it against the end of its sequence. An iterator which points to an element is said to be valid and can be dereferenced using *, [] or →.
What are Lists?
What are Lists? - List class supports a bidirectional linear list. Unlike a vector, which supports random access....
What are associate containers?
What are associate containers? - Containers are objects that hold other objects. An associative container stores pair of values...
What is stream iterator? - C++
What is stream iterator? - Iterators are the glue that hold the container and algorithms together...
Post your comment