getNext
Tomek Sowiński
just at ask.me
Fri Jul 23 13:16:17 PDT 2010
Dnia 13-07-2010 o 06:38:55 Andrei Alexandrescu
<SeeWebsiteForEmail at erdani.org> napisał(a):
> I've just had an idea that is so dark and devious, I was almost afraid
> to try it. But it works like a charm. Consider:
> T * getNext(R, E)(ref R range,
> ref E store = *(cast(E*) alloca(E.sizeof))
> {
> ...
> }
> With this, allocating a dummy buffer on caller's stack is automated, so
> client code can just write:
> for (T * p; (p = getNext(r)); ) {
> ... process *p ...
> }
> I feel dirty.
What's wrong with foreach(e; r) that you want to play dirty? The compiler
is here to help.
Tomek
More information about the Digitalmars-d
mailing list