RFC on range design for D2

bearophile bearophileHUGS at lycos.com
Tue Sep 9 15:26:49 PDT 2008


Andrei Alexandrescu:
> In Phobos things will be something like:

List!(Filedesc) lst;
for (auto r = lst.all; !r.isEmpty; ) {
     if (should_remove)
          r = lst.erase(take(1, r));
     else
          r.next;
}

It may be better to invent and add some sugar to that, and foreach helps, maybe something like:

List!(Filedesc) lst;
foreach (ref r; lst.all) {
     if (predicate(lst.item(r)))
          r = lst.erase(r);
     else
          r = r.next();
}

I think that code of mine isn't good yet :-)

Bye,
bearophile


More information about the Digitalmars-d-announce mailing list