Re: Iterators in Java and C++
In article <9c3fd6d1-6eb0-4691-a79c-059960377100
@q10g2000prf.go oglegroups.com> , chsalvia@gmail. com says...
C++ 0x should be somewhat more to your liking then -- it introduces
Ranges. A range is essentially equivalent to a pair of iterators; it
represents a range of objects (typically, but not necessarily, in a
container).
[ ... ]
True. I think an iterator containing a lot of data is fairly unusual,
but if/when you need to create an iterator that contains a lot of data
that's never used, that's obviously not particularly efficient.
--
Later,
Jerry.
The universe is a figment of its own imagination.
In article <9c3fd6d1-6eb0-4691-a79c-059960377100
@q10g2000prf.go oglegroups.com> , chsalvia@gmail. com says...
Overall, I usually prefer C++ iterators to Java style iterators for
subjective, aesthetic reasons. However, there are times when I
question the sanity of having two iterator objects instead of one.
subjective, aesthetic reasons. However, there are times when I
question the sanity of having two iterator objects instead of one.
Ranges. A range is essentially equivalent to a pair of iterators; it
represents a range of objects (typically, but not necessarily, in a
container).
[ ... ]
Especially, in a case where you have a rather complex iterator object
that has a lot of member variables, and so takes up a lot more stack
space than a simple pointer. Usually, the "end" iterator object is
only there so you can compare a single member variable. The rest of
the member variables in the "end" iterator object are usually unused.
While there's probably not any measurable performance loss, the Java-
style interface would me more efficient in theory, because you
wouldn't have the extra "end" iterator with all the useless member
variables it stores.
that has a lot of member variables, and so takes up a lot more stack
space than a simple pointer. Usually, the "end" iterator object is
only there so you can compare a single member variable. The rest of
the member variables in the "end" iterator object are usually unused.
While there's probably not any measurable performance loss, the Java-
style interface would me more efficient in theory, because you
wouldn't have the extra "end" iterator with all the useless member
variables it stores.
but if/when you need to create an iterator that contains a lot of data
that's never used, that's obviously not particularly efficient.
--
Later,
Jerry.
The universe is a figment of its own imagination.
Comment