Jerry Coffin said:
In message <MPG.214c85e97bc4ed839899b5@news.sunsite.dk>, Jerry Coffin
<jcoffin@taeus.com> writes
[ ... ]
e.g. the one under discussion.
Yes, but not for many others.
Then one wouldn't use it in those situations.
[ ... ]
Naturally, hence the word "infinite" above. That's what software design
is all about. You need to provide a class that most appropriately models
the relevant concept. "Bounded sequence" and "infinite sequence" are
different concepts, so the solutions are likely to be different too.
I can't agree. There doesn't seem to be any situation (at least with the
standard algorithms) that actually requires an infinite sequence -- some
require it to be bounded, and others don't care. At least if memory
serves, the one I provided CAN act like an infinite sequence -- you can
increment the iterator and look at the value as often as you want to.
It's only as "infinite" as your "index" type: size_t, or whatever. Not
likely to be a problem, but not truly infinite.
It
also, however, allows you to check the iterator against a bound whenever
you want to, so it can act as either a bounded or unbounded sequence. I
can't see any advantage for only providing an unbouded sequence over
providing one that can act either bounded or unbounded as the situation
requires.
Simplicity. Your solution adds complexity because you need to model the
entire sequence and how to handle the bounds, whereas mine only needs to
model a single _element_ of the sequence (all elements are identical,
don't forget).
You need a pseudo-vector with a constructor and begin() and end() and
operator[] and an iterator with constructor and increment and
comparison, whereas I only need a pseudo-iterator. Having abstracted the
concept of iterator, I don't have to concern myself with the mechanics
of the sequence it iterates over. I don't have to code and test a vector
as well.