Dnia 13-07-2010 o 06:38:55 Andrei Alexandrescu <[email protected]> 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

Reply via email to