Flag & byLine confusion.
Paul Backus
snarwin at gmail.com
Sat Dec 19 23:36:58 UTC 2020
On Saturday, 19 December 2020 at 23:16:00 UTC, Rekel wrote:
> After reading most of the tour.dlang.org website, I was
> completely surprised & confused encountering 'KeepTerminator',
> a 'Flag' used by the File.byLine function. With no examples
> denoting how to use it.
>
> Most confusing was the way the documentation (website &
> in-editor) used;
> 1. Yes.keepTerminator
> 2. KeepTerminator.yes
> 3. Flag!"keepTerminator".yes
> & Don't get me started on the autocomplete trying to get me to
> use KeepTerminator.Flag.yes (VSCode & code-d)
Flag is a templated enum, documented here:
http://phobos.dpldocs.info/std.typecons.Flag.html
It has two members, Flag!"name".yes and Flag!"name".no. As
explained in the documentation linked above, Yes and No are
structs that provide (slightly) less verbose aliases for these
enum members. The documentation for Yes and No is here:
http://phobos.dpldocs.info/std.typecons.Yes.html
http://phobos.dpldocs.info/std.typecons.No.html
> Even further confused by the in-editor documentation, is this
> function a template?:
> "
> byLine(Terminator = char, Char = char) (KeepTerminator
> keepTerminator = No,keepTerminator, Terminator terminator =
> '\\n')
> "
Yes, it is a template. If you look at the section on "parameters"
in the documentation
http://phobos.dpldocs.info/std.stdio.File.byLine.1.html#parameters
...you can see that the template parameter Char is the character
type used for the lines. So if you wanted to have lines of wchar
instead of char, you could use `.byLine!(wchar, wchar)`.
More information about the Digitalmars-d-learn
mailing list