foreach UFCS
Rene Zwanenburg via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Thu Mar 31 06:48:14 PDT 2016
On Thursday, 31 March 2016 at 13:39:25 UTC, ixid wrote:
> What is going on with UFCS and foreach?
>
> foreach(i;0..5).writeln;
>
> This prints five line breaks.
>
> foreach(i;0..5).i.writeln;
>
> This will not compile.
>
> foreach(i;0..5).writeln(i);
>
> This writes out 1 to 4 on separate lines. Is this supposed to
> work? I thought a.b would be rewritten to b(a) with UFCS but
> writeln(foreach(i;0..5)) is nonsensical and does not compile
> and should be the same as foreach(i;0..5).writeln;
The compiler interprets it as a foreach without curly braces.
With curlies it would look like:
foreach(i; 0..5)
{
.writeln();
}
In this context the dot means the writeln lookup should happen
from the module level scope.
More information about the Digitalmars-d-learn
mailing list