|
Boost : |
From: Neal D. Becker (nbecker_at_[hidden])
Date: 2003-04-14 14:51:48
On Saturday 12 April 2003 09:15 pm, David Abrahams wrote:
> "Neal D. Becker" <nbecker_at_[hidden]> writes:
> > The most promising IMHO is cycle_iterator, which is an adaptor submitted
> > by Gennadiy Rozental. I believe this is almost ready for a real boost
> > submission. Last we left it, there were some questions of the semantics
> > of the "distance" between iterators. In any case, the "distance" between
> > iterators in a cyclic buffer is fuzzy.
>
> A cyclic buffer can never be full, because full is the same as empty
> (begin == end). Therefore, it can always be re-mapped into an
> equivalent vector by moving all the initial non-empty elements to the
> back, and distance is perfectly well-defined.
>
> Where's the fuzziness?
I thought the distance between 2 iterators is normally interpreted as a signed
quantity. In the case of the cyclic iterator, we have an ambiguity. In
general, for a container of size N, the distance from "a" to "b" can be:
d = b - a + mN
where m is an arbitrary integer.
I believe it is most useful to always use the interpretation:
d = (b >= a) ? (b - a) : (b - a + N)
That is, the distance from a to b is the same as the number of times I need to
increment from a to b (assuming of course that increment has the usual
meaning).
Note that this also means that b - a is always positive.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk