How is chunkBy supposed to behave on copy
Paul Backus
snarwin at gmail.com
Wed Mar 18 15:44:44 UTC 2020
On Wednesday, 18 March 2020 at 14:57:41 UTC, Dukc wrote:
> So the question is, how should it behave? I have looked at the
> implementation, it should be trivial to have it to use value
> semantics. On the oher hand, someone may rely on the present
> behaviour.
>
> [1]
> https://dlang.org/phobos/std_algorithm_iteration.html#.chunkBy
As I understand it, the result of using a range after copying it
is unspecified, and relying on any particular behavior in that
case is a bug. So changing the behavior will only break code that
is (in some sense) "already broken."
Of course, given the above, the question of how it "should"
behave is rendered moot. If you're copying a range, you must
either use .save, or only use the copy and not the original from
that point forward. In fact, if you want to catch as many errors
as possible at compile time, the strictest approach would be to
mark the range as non-copyable (@disable this(this)) and require
the use of either .save or move to copy it.
More information about the Digitalmars-d
mailing list