Answer the question
In order to leave comments, you need to log in
How is ranged for iterated?
To use ranged for , a container must satisfy a number of conditions. In particular, for a container, you can define functions begin( __range )
and end( __range )
available via ADL .
But what if linear iteration over the container is not possible? begin
What should the and functions return in this case end
?
Answer the question
In order to leave comments, you need to log in
Iterators are an abstraction created in order to be able to use the same approach to bypass fundamentally different containers.
An iterator implementation is a class that implements a particular interface, as you wrote. Inside the class, implement it however you want, store states, references, counters in private data members of the iterator class, etc. etc. begin with end must return a reference to the corresponding iterator. begin and end are not part of the iterator interface.
Learn materiel.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question