stdio.lines doesn't have popFront, but works with foreach
Steven Schveighoffer via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Thu Dec 11 13:01:48 PST 2014
On 12/11/14 3:21 PM, Andrew Klaassen wrote:
> On Thursday, 11 December 2014 at 20:17:50 UTC, bearophile wrote:
>> Andrew Klaassen:
>>
>>> The docs for stdio.lines say that it's a struct. stdio.lines works
>>> with foreach.
>>
>> If you want a range use "myfile".File.byLine or "myfile".File.byLineCopy.
>>
>> Bye,
>> bearophile
>
> I know that there are other ways that'll work. I was just curious about
> what appears to be a surprise in the way that foreach interacts with
> stdio.lines.
Look down a little bit further on that document, you will see the
section titled "Foreach over Structs and Classes with opApply"
Hm.. I note the incorrect statement "If the range properties don't
exist, then the foreach is defined by the opApply member function". This
is not exactly true, the foreach statement defaults to opApply first,
and will use range functions only if that doesn't exist.
FYI, the reason stdio.lines works that way is because in general, ranges
can only give you one value, but stdio.lines wants to give you the line
number too.
-Steve
More information about the Digitalmars-d-learn
mailing list