-
-
Notifications
You must be signed in to change notification settings - Fork 741
fix Issue 14373 - std.range.refRange doesn't work on mere input ranges #3123
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
+/ | ||
auto refRange(R)(R* range) | ||
if(isForwardRange!R && !is(R == class)) | ||
if(!is(R == class)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if(isInputRange!R && !is(R == class))
or
static assert(isInputRange!R, "refRange only works with ranges");
Wrong types should be detected as early as possible.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
I suspect this is unhelpful. I might be wrong. The difference between a Thus, this PR fixes a problem that does not exist. There is no improvement here. |
I believe the ForwardRange is just an InputRange with the save method to take a snapshot of its current state. You can see this in the Phobos snippet:
As to whether this is a useful change, I'll leave that to those better versed in D. |
You are both right and missing the point. The |
When reading from a socket, you have to save the read data somewhere. It should be fine to store it directly in the range struct. The struct then doesn't have reference semantics: popFront on one copy won't change the front of another copy. |
A Certainly, you can store data you read from a socket. If you store the data, however, you can (and need to) supply a |
From the article: "IsDone checks for end-of-input and fills a one-element buffer held inside the range object, CurrentItem returns the buffer" It's that one-element buffer I'm talking about. If it's part of the range struct, then popFront on a copy doesn't alter the original front => no reference semantics. |
You are certainly right here. A one element cache changes the behavior. My perception is, implicit caching in input ranges does not work too well and tends to be squeezed out of phobos. See for example the non-caching Still, I stand corrected. Your patch addresses an issue. I am not convinced the issue should be addressed, however. On the contrary, I feel this does not belong to the standard library. Your mileage may vary. |
Makes sense for InputRanges with buffering, e.g. vibe.d's StreamInputRange. |
Auto-merge toggled on |
fix Issue 14373 - std.range.refRange doesn't work on mere input ranges
https://issues.dlang.org/show_bug.cgi?id=14373