News for hackers. Stuff that matters.
Re:Writing a custom iterator in modern C++ by fjfaase on Monday December 21, 2020 @05:00AM (#25493505)
Iterators are a very powerful concept, however, it is very cumbersome and often impossible, to implement some interesting iterator based on the standard iterators. This stems from the idea that any iterator can based on a single pointer and use pointer comparison for indicating the start and the end of the contents.

The most common case, are forward output iterators, for which I usually define a class that defines the methods more and next, that can be used as:

for (MyIterator it(data); it.more(); it.next())

Re:Writing a custom iterator in modern C++ by Olipro on Monday December 21, 2020 @05:47AM (#25493740)
An iterator is a class. It can contain any private data you desire and mutate in any wonderful and/or stupid ways you desire.

How it decides to compare equal to the .end() instance is also your call. Your example is not a compliant iterator (as in, wouldn't work in a range-based for loop) - yet the same behaviour would be achievable through your own operator++() and operator bool(),

Re:Writing a custom iterator in modern C++ by fjfaase on Monday December 21, 2020 @06:33AM (#25493951)
I agree, but I feel it is a little sad that such a powerful programming concept as an iterator is hard to implement in C++ if you want to make full use of it. Other program languages have made better choices with respect to this and allow you to write cleaner, shorter code.
Re:Writing a custom iterator in modern C++ by saurik on Monday December 21, 2020 @01:50PM (#25498037)
Why not just use those two operators instead of more and next?