Passing a byLine as an argument to InputRange

Jeff massung at gmail.com
Thu May 13 17:07:51 UTC 2021


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, even though the documentation states it's an 
InputRange.

```
class Foo {
   private InputRange!string source;

   this(InputRange!string s) {
     source = s;
   }

   // do stuff with it
}

new Foo(File("stuff.txt").byLine);

// Error constructor Foo.this(InputRange!string) is not callable 
using argument types (ByLineImpl!(char, char))
```

I have to believe this is possible. I'm thinking maybe I need to 
template the constructor with something like:

```
this(R)(R s) if (isInputRange!R)
```

But, then I seem to have 2 problems:

1. I haven't ensured it's an InputRange!string
2. I've just punted the problem up a level, because my member 
variable doesn't work.

Any help appreciated. Thanks!



More information about the Digitalmars-d-learn mailing list