RFC on range design for D2
Andrei Alexandrescu
SeeWebsiteForEmail at erdani.org
Tue Sep 9 16:05:44 PDT 2008
bearophile wrote:
> 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 :-)
Wow, that's risky. foreach bumps r under the hood, so you'll skip some
elements.
Andrei
More information about the Digitalmars-d-announce
mailing list