3 ms·
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 t
by Olipro 6y ago
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(),
- fjfaase 6y agoI 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.
- saurik 6y agoWhy not just use those two operators instead of more and next?