Unexpected foreach lowering

Lodovico Giaretta via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Wed Aug 10 11:47:02 PDT 2016

On Wednesday, 10 August 2016 at 18:38:00 UTC, Ali Çehreli wrote:
> RangeWrapper does not provide the InputRange interface, so the 
> compiler uses 'alias this' and iterates directly on the member 
> range.
> I tried making RangeWrapper an InputRange but failed. It still 
> uses 'range'.
> // Still fails with these:
>     @property bool empty() {
>         return range.empty;
>     }
>     void popFront() {
>         range.popFront();
>     }
> I don't know how the decision process works there.
> Ali

That's strange, as RangeWrapper works correctly if instantiated 
with any underlying range EXCEPT std.container.Array.
Also, RangeWrapper does provide the InputRange interface, 
partially directly and partially with alias this. RangeWrapper 
should be "opaque", as it should not matter whether the methods 
needed for the InputRange interface are defined directly or 
inherited with alias this.

More information about the Digitalmars-d-learn mailing list