Iterators Must Go

Walter Bright newshound1 at digitalmars.com
Fri May 8 21:15:19 PDT 2009


Steven Schveighoffer wrote:
> You're assuming an iterator does not know its bounds.

That's right. That's the usual design, which is based on the pointer 
model. Pointers do not know their limits.

> Maybe I should 
> call it something other than iterator.  How about cursor?

Or range? <g>


> There are definite reasons to use containers in ways that don't involve 
> std.algorithm, where something that has the easy ability to move back 
> and forth N times without weird subrange operations.
> 
> I'm thinking of a structure with either a pointer to the container for 
> bounds checking, or a range and pointer combined (where the invariant is 
> that the pointer is always within the range).
> 
> I'm not saying ranges are not great, i think they are a HUGE step 
> forward, but the statement "Iterators must be eliminated" may be too 
> harsh.  Perhaps the unchecked iterator, yes (but you may want to allow 
> it in certain performance-critical code).

If you had an iterator that knew its beginning and end, then the whole 
paradigm of:

    for (iterator i = begin; i != end; i++)

doesn't make much sense because of the redundancy.



More information about the Digitalmars-d mailing list