"Cannot infer argument types" for foreach over byLine
Steven Schveighoffer via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Mon Jan 26 05:28:39 PST 2015
On 1/24/15 11:15 AM, Meta wrote:
> On Saturday, 24 January 2015 at 08:44:45 UTC, Ali Çehreli wrote:
>> On 01/24/2015 12:14 AM, Meta wrote:
>>
>> > import std.stdio;
>> >
>> > void main()
>> > {
>> > foreach (i, line; file.byLine())
>>
>> Unless the range itself provides explicitly, automatic counter is
>> available only for arrays. Otherwise, you have to enumerate yourself. ;)
>
> Hmm, how have I not known that until now? I thought that feature worked
> for all ranges. Thanks.
It would be confusing. Imagine this scenario:
auto l = file.byLine();
l.popFront();
foreach(i, line; l)
Now, the line numbers are off by one, because the ByLine struct does not
track them.
-Steve
More information about the Digitalmars-d-learn
mailing list