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

Steven Schveighoffer via Digitalmars-d digitalmars-d at puremagic.com
Fri Nov 25 07:46:15 PST 2016


On 11/25/16 8:24 AM, Jonathan M Davis via Digitalmars-d wrote:
> 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.

This is a misunderstanding. The missing parens is for *usage* of the 
range, not *definition* of the range. It won't affect isInputRange at all.

This case you have of defining a popFront member variable with opCall -- 
don't do that, it will break things (I'm sure there are already many 
places where popFront is called without parens). I don't think that's a 
case that we need worry about.

-Steve.


More information about the Digitalmars-d mailing list