OT: for (;;) {} vs while (true) {}

Jonathan M Davis via Digitalmars-d digitalmars-d at puremagic.com
Fri Nov 25 05:24:19 PST 2016


On Friday, November 25, 2016 07:59:07 Andrei Alexandrescu via Digitalmars-d 
wrote:
> On 11/25/2016 07:53 AM, Dennis Ritchie wrote:
> > https://github.com/dlang/phobos/blob/master/std/algorithm/comparison.d#L
> > 591
> I like that function. If I were to review it now, I'd approve with these
> nits:
>
> * drop the parens for popFront

I would point out that technically, that breaks the range API. isInputRange
requires that popFront be callable with parens, but it does not require that
it be callable without parens. So, someone could define popFront as a public
member variable with an overloaded opCall. That would not compile if it were
used with code that called popFront without parens even though it would
compile with isInputRange.

Now, realistically, no one is going to do that, so it probably doesn't
matter. But it seems to me that in general, when dealing with a trait like
isInputRange which tests that a particular syntax is used, it's just safer
to use that syntax rather than using parens where it doesn't or not using
parens where it does.

- Jonathan M Davis



More information about the Digitalmars-d mailing list