DMD 0.170 release

Frits van Bommel fvbommel at REMwOVExCAPSs.nl
Tue Oct 17 12:27:39 PDT 2006


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)



More information about the Digitalmars-d-announce mailing list