DMD 0.170 release
Sean Kelly
sean at f4.ca
Tue Oct 17 14:09:34 PDT 2006
Frits van Bommel wrote:
> Walter Bright wrote:
>> Hasan Aljudy wrote:
>>> Also, since foreach already takes two arguments (int i, T t) that is,
>>> index and element, you can add a third argument, of bool type, with
>>> the meaning "start in reverse mode"
>>> foreach( true, i, d; "Hello" )
>>> {
>>> writefln( d );
>>> }
>>>
>>> should print:
>>> o
>>> l
>>> l
>>> e
>>> H
>>
>> That would work, and something like it has been suggested before, but
>> it is too obscure looking. When someone sees "foreach_reverse", I
>> think it'll be very clear what's going on.
>
> There's no need to use booleans (at least, not directly):
>
> enum Ordering : bool { forward, backwards, reversed = backwards }
>
> That should produce much more readable code, but work the same. Can be
> done right now, except you can't overload opApply for arrays :(. (Tell
> me if I'm wrong, but I tried and it didn't work)
I like that the current implementation will produce a compile error if
an object without opApplyReverse is used as an aggregate in
foreach_reverse. If the syntax were to change, I wouldn't want to push
this checking to run-time (which it seems a parameter-based method might
do).
Sean
More information about the Digitalmars-d-announce
mailing list