Passing a byLine as an argument to InputRange
Ali Çehreli
acehreli at yahoo.com
Thu May 13 18:29:08 UTC 2021
On 5/13/21 10:07 AM, Jeff wrote:
> I have a class where I'd like to supply it with an InputRange!string.
> Yet, for the life of me I can't seem to pass to it a File.byLine
As Adam said, your range elements need to be converted to string e.g.
with 'text' (the same as to!string). However, you must also create a
dynamic InputRange!string object for dynamic polymorphism that
InputRange provides. And that's achieved by function inputRangeObject():
import std.range;
import std.stdio;
import std.algorithm;
import std.conv;
class Foo {
private InputRange!string source;
this(InputRange!string s) {
source = s;
}
// do stuff with it
}
void main() {
new Foo(inputRangeObject(File("stuff.txt").byLine.map!text));
}
Ali
More information about the Digitalmars-d-learn
mailing list