On 04/16/2018 06:15 AM, Shachar Shemesh wrote:
Input ranges provide no guarantees about copying the range itself. If
you do it and expect *anything* (which it seems you do), you have a bug.
If you need to copy the range itself, you absolutely need to require a
forward range.
A forward range with ref front absolutely promises that both iterations
reference the same elements.
I find myself sincerely hoping that you are making these examples up in
order to win this discussion turned into an argument for some reason,
instead of the way phobos is actually written, because if you're right
phobos is *broken*.
The good news is that if Phobos is broken, this is a great way to flush
out the places it's broken. Let's add UTs calling all Phobos functions
accepting input ranges (as opposed to forward ranges) with non-copyable
ranges (i.e. - the range itself is non-copyable) and fix the compilation
errors. This shouldn't take more than a few days to do.
I'm currently attempting something similar: fix Phobos to work with
RefRange. RefRange is copyable, but assignment is weird. Assignment
isn't part of the range interface, so I'm replacing it with `move`:
https://issues.dlang.org/show_bug.cgi?id=18657
https://github.com/dlang/phobos/pull/6346
That PR doesn't fix all of Phobos, it's just a start. Going over all of
Phobos (and getting it merged) might take a while.
Thinking about it, those `move`s probably fix the code for non-copyable
ranges as well. There might be considerable overlap here.