Tricky semantics of ranges & potentially numerous Phobos bugs
bearophile
bearophileHUGS at lycos.com
Tue Oct 16 07:23:26 PDT 2012
Jonathan M Davis:
> And actually, it seems to me that issues like this make it look
> like it was a
> mistake to make ranges like ByLine ranges in the first place.
> They should have
> just defined opApply so that they'd work nicely in foreach but
> not with range-
> based functions. They're clearly not going to work with a _lot_
> of range-based
> functions.
I like byLine() to be a range, so it's compatible with
std.algorithm stuff. But a short time after the creation of
byLine() I suggested to make it copy (dup) lines on default and
not copy them on request, this means:
auto lineBuff = "foo.txt".File().byLine().array();
==> good result
auto lineBuff = "foo.txt".File().byLine!false().array();
==> doesn't copy, garbage result.
I design my ranges like that. It's safe because on default (or if
you don't know what you are doing) it copies, and it's a bit
slower. When you know what you are doing and you want more speed,
you disable the copy with a compile-time argument.
Bye,
bearophile
More information about the Digitalmars-d
mailing list