RFC on range design for D2
Denis Koroskin
2korden at gmail.com
Wed Sep 10 02:31:56 PDT 2008
On Wed, 10 Sep 2008 01:56:40 +0400, Andrei Alexandrescu
<SeeWebsiteForEmail at erdani.org> wrote:
> Andrei Alexandrescu wrote:
>> Manfred_Nowak wrote:
>>> Benji Smith wrote:
>>>
>>>> Given the use of "getNext", I think "hasNext" is a more natural
>>>> choice
>>>
>>> clapping hands.
>> Walter would love that.
>> for (R r = getR(); r.hasNext; r.next) { ... }
>> Look ma, no negation! Oops, I just materialized one with the
>> exclamation sign.
>
> I just discovered a problem with that. hasNext implies I'm supposed to
> call next to get the thingie. It should be hasFirst, which is less
> appealing.
>
> Andrei
I usually implement my iterators as follows:
interface Iterator(T) {
bool isValid();
T value();
void moveNext();
}
Usage:
auto it = ...;
while (it.isValid()) {
auto value = it.value();
it.moveNext();
}
or
for (auto it = ...; it.isValid(); it.moveNext()) {
auto value = it.value();
}
More information about the Digitalmars-d-announce
mailing list