Unexpected foreach lowering

Ali Çehreli via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Wed Aug 10 12:37:39 PDT 2016


On 08/10/2016 11:47 AM, Lodovico Giaretta wrote:
> 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.

A quick read reveals popFront() is implemented only for bool Arrays. 
That explains the issue.

I don't know whether it's an oversight.

Ali



More information about the Digitalmars-d-learn mailing list