Ranges, constantly frustrating
Steven Schveighoffer
schveiguy at yahoo.com
Tue Feb 11 11:16:31 PST 2014
On Tue, 11 Feb 2014 05:10:27 -0500, Regan Heath <regan at netmail.co.nz>
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.
This is only available using opApply style iteration. Using range
iteration does not give you this ability.
It's not a permanent limitation per se, but there is no plan at the moment
to add multiple parameters to range iteration.
One thing that IS a limitation though: we cannot overload on return
values. So the obvious idea of overloading front to return tuples of
various types, would not be feasible. opApply can do that because the
delegate is a parameter.
-Steve
More information about the Digitalmars-d-learn
mailing list