getNext
Andrei Alexandrescu
SeeWebsiteForEmail at erdani.org
Mon Jul 12 20:48:05 PDT 2010
I think I figured out a comfortable and all-encompassing means to define
a simplified interface for an input range.
Currently input ranges need to define empty, front, and popFront. That
works but it's a bit heavy for simple input ranges. We've been
discussing simplified interfaces in this group but couldn't find one
that satisfied all use cases.
Consider this:
T* getNext(R, T)(ref R range, ref T item);
Semantics: if the range wants to expose addresses of its elements, it
returns a pointer to the current element and also advances to the next
element. Otherwise (i.e. the range does not have or does not want to
expose addresses of its elements), the range fills "item" with the
current value, again moves on to the next value, and returns &item.
In all cases, when there are no more elements in the range, getNext
returns null.
getNext is easy to define for e.g. arrays and files. How does it sound?
Does it bring significant simplification?
Andrei
More information about the Digitalmars-d
mailing list