|
Boost : |
From: AlisdairM (alisdair.meredith_at_[hidden])
Date: 2003-11-20 04:09:27
John Torjo <john.lists_at_[hidden]> wrote in
news:3FBD03CA.6000601_at_[hidden]:
Lots to think about, but I'll just come back on one specific point that I
think I should have explained better ;¬ )
> I don't agree here. A forward range still has two iterators.
> The fact that you don't have to deal with them directly, that's the
> added bonus ;)
>>> [istream_iterator example]
> I'm not sure I understand. The way we see ranges is still as a pair of
> iterators. There still must be a begin() and an end(), for us to have
> a range. How you implement end() internally it's still up to you (the
> implementor of the iterator class).
>
> You should note the fact that if we take out the requirement of a
> range being a pair of iterators, how could you use it in algorithms?
The idea I am pushing for here is that ranges ARE NOT pairs of iterators.
Rather, a pair of iterators happens to make a good representation of a
range, but may not be the only one.
Taking the example of a forward range. All we really need is a starting
point (not sure there is a substitute for iterator here) and an 'end test'.
By default, a range is a pair of iterators and 'end test' is "current
position == end()"
However, for an example like an istream_range an end test is much better
expressed in terms of the underlying stream. We currently fake this by
making a default constructed istream_iterator act as a sentry, but it is a
nasty hack.
By removing the condition that all ranges have a valid end() iterator at
construction time we open up more potential for forward ranges.
So the requirements on a forward range are:
Start position is a forward_traversal iterator
Some test exists to know if the current position can advance
Algorithms where forward traversal ranges are appropriate can be expressed
in terms of this simpler interface without ever referring to end()
directly.
Insisting on the two-iterator implementation (or even an end() function)
seems to overspecify the requirements.
OTOH, I quite agree that random access ranges are going to need both
iterators.
AlisdairM
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk