Ranges, constantly frustrating

Jakob Ovrum jakobovrum at gmail.com
Tue Feb 11 02:20:54 PST 2014


On Tuesday, 11 February 2014 at 10:10:27 UTC, Regan Heath wrote:
> Things like this should "just work"..
>
> File input ...
>
> auto range = input.byLine();
> while(!range.empty)
> {
>   range.popFront();
>   foreach (i, line; range.take(4))  //Error: cannot infer 
> argument types
>   {
>     ..etc..
>   }
>   range.popFront();
> }
>
> Tried adding 'int' and 'char[]' or 'auto' .. no dice.
>
> Can someone explain why this fails, and if this is a permanent 
> or temporary limitation of D/MD.
>
> R

See this pull request[1] and the linked enhancement report.

Also note that calling `r.popFront()` without checking `r.empty` 
is a program error (so it's recommended to at least put in an 
assert).

[1] https://github.com/D-Programming-Language/phobos/pull/1866


More information about the Digitalmars-d-learn mailing list