Please help me understand this function signature: std.stdio.File.byLine
Scotpip
geoff at variosoft.co.uk
Thu Jul 15 18:08:45 UTC 2021
Hi folks
Settling down to write my first app but have come to a grinding
halt. This is my first system-level language so I'm afraid I'll
be asking some naïve questions.
All I'm trying to do is read a text file with Windows line
endings into an array for line-by-line processing.
The relevant function appears to be
[std.stdio.File.byLine](https://dlang.org/library/std/stdio/file.by_line.html).
The default isn't breaking the lines properly, so I have to pass
in the line ending. But the signature has me baffled:
```
auto byLine(Terminator, Char) (
KeepTerminator keepTerminator = No.keepTerminator,
Terminator terminator = '\x0a'
)
if (isScalarType!Terminator);
auto byLine(Terminator, Char) (
KeepTerminator keepTerminator,
Terminator terminator
)
if (is(immutable(ElementEncodingType!Terminator) ==
immutable(Char)));
```
To specify the line ending, it appears to be asking for a type
"Terminator" which I can't find in the library. Doing the obvious
doesn't work:
```
// Err: cannot deduce function from argument types
myFile.byLine(`\r\n`);
```
Also, how would you specify the Char type as a parameter?
The examples are unenlightening as they only show the default
case, so any help would be much appreciated. Any wider tips on
how to read these cryptic signatures would be a bonus!
More information about the Digitalmars-d-learn
mailing list