Are all pointers considered iterators?

That was a question on my exam, and the answer is that all pointers are iterators, but not all iterators are pointers. Why is this so?

In a statement, for example:

int *p = new int(4);

How can p be considered an iterator at all?

+4
source share
1 answer

An “iterator” is an abstract concept that describes a specific set of operations that a type must support with specific semantics.

Pointers are iterators because they fulfill the concept of iterator (and, even stronger, a random access iterator ), for example operator++, to go to the next element and operator *to access the basic element.

[p, p+1)

, , , . ( , - .) "" , , .

, , : , std::list<T>::iterator. , , operator[].

+10

Source: https://habr.com/ru/post/1664025/


All Articles