Unable to convert a MapResult to an InputRange.
Jake Pittis via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Sun Sep 18 18:13:19 PDT 2016
````
import std.stdio;
import std.array;
import std.algorithm;
import std.range;
InputRange!string keys(int[string] foo) {
return foo.byPair.map!(p => p[0]);
}
void main() {
int[string] foo;
foo["lol"] = 1;
foo["wat?"] = 2;
keys(foo).each!(p => writeln(p));
}
````
The above code produces an `cannot implicitly convert expression
(map(byPair(foo))) of type MapResult!(__lambda2,
MapResult!(__lambda2, Result)) to
std.range.interfaces.InputRange!string` error.
If I replace `InputRange!string` with `auto`, it compiles.
I'm intending to use InputRange!string as a return type in an
interface so I can't use auto.
````
interface bar {
InputRange!string keys();
}
````
I don't want to convert it to an array because of the allocation.
Isn't the whole point of ranges to pass around a lazy interface
without having to allocate any extra memory? Why can't I cast the
output of map to an InputRange or something similar?
Thanks for the help. :) Phobos documentation is lovely but I've
been finding errors similar to this to be quite frustrating.
More information about the Digitalmars-d-learn
mailing list