[Development] Future of java-style iterators?
Marc Mutz
marc.mutz at qt.io
Tue Dec 5 10:16:49 CET 2023
On 05.12.23 10:06, Giuseppe D'Angelo via Development wrote:
> Il 05/12/23 03:52, Kevin Kofler via Development ha scritto:
>> Marc Mutz via Development wrote:
>>> Until then, either you want to be notified of sub-optimal APIs asap,
>> What is "suboptimal" about Java-style iterators, other than that they
>> do not
>> work the same way as the STL ones? I find the Java-style iterators to be
>> easier to use and less error-prone than the STL-style ones (which, as I
>> understand it, is why they were originally added to Qt to begin with).
>
> The huge downside is that they don't work with any algorithms or
> range-based facilities. They work, in their little bubble.
Const ones are ok-ish, except they need to maintain two iterators
instead of one, like STL ones, and the state depends on the history
(specifically, whether next() or previous() was called). The problem is
the Mutable ones. Which element does setValue() work on? Which one does
remove() remove? I don't want to look it up, but I remember there was
some conceptional problem there.
Also, remove() in a loop is quadratic, and since no-one ever made
Java-style iterators for C arrays and STL containers, and they hard-code
the name of the container in the class name without containers providing
a typedef for them, they cannot possibly be used in generic code.
Thanks,
Marc
--
Marc Mutz <marc.mutz at qt.io>
Principal Software Engineer
The Qt Company
Erich-Thilo-Str. 10 12489
Berlin, Germany
www.qt.io
Geschäftsführer: Mika Pälsi, Juha Varelius, Jouni Lintunen
Sitz der Gesellschaft: Berlin,
Registergericht: Amtsgericht Charlottenburg,
HRB 144331 B
More information about the Development
mailing list