D
D
Dima Sokolov2018-04-29 13:41:57
C++ / C#
Dima Sokolov, 2018-04-29 13:41:57

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? beginWhat should the and functions return in this case end?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
R
res2001, 2018-04-29
@dimka11

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.

V
Vitaly, 2018-04-29
@vt4a2h

I advise you to go to the documentation and read about the types of iterators and what they are.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question