Comma operator = broken design

Robert Jacques sandford at jhu.edu
Sun Dec 11 18:18:24 PST 2011


On Sun, 11 Dec 2011 20:25:07 -0500, Jonathan M Davis <jmdavisProg at gmx.com> wrote:

> On Sunday, December 11, 2011 20:19:11 Robert Jacques wrote:
>> A lot (all?) of for loop use cases seem to actually work in tuple form. For
>> instance,
>>
>> for(; cond; tuple(++x, y *= 2) ) {}
>>
>> Will behave as expected, although there might be a performance issue.
>
> What if one of the expression's result is void?
>
> All in all, I think that it's ludicrous to consider changing the semantics of
> for loops to use a tuple instead of the comma operator. It's one thing to
> consider eliminating the comma operator outside of for loops. It's yet another
> to consider adding built-in templates beyond that, and it's going _way_ too
> far to change the semantics of the for loop as part of that IMHO.
>
> for loops should be left exactly as they are, regardless of what happens with
> the comma operator outside of for loops.
>
> - Jonathan M Davis
>

Ah, thank you. I was observing that my standard for loop syntax actually had the same effective meaning under traditional and tuple semantics, and wasn't seeing the counter example. But,

for(; !a.empty && b.empty; a.popFront, b.popFront) {}

would never work as a tuple.


More information about the Digitalmars-d mailing list