-
-
Notifications
You must be signed in to change notification settings - Fork 744
Fixed issue #10019 #1282
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
Fixed issue #10019 #1282
Conversation
…o ref parameters for the ranges. Unit tests have been added to match each modification.
My knowledge of std.conv is quite limited, so comments on this patch, perhaps involving the different variations of parse I'm not familiar with, are very welcome. |
@@ -24,6 +24,10 @@ import std.algorithm, std.array, std.ascii, std.exception, std.math, std.range, | |||
std.utf; | |||
import std.format; | |||
|
|||
version(unittest) { | |||
import std.container; | |||
} |
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.
You should be able to import this directly inside the rel event unittest bloc. It limits the scope more.
I was wondering if there would be any damaging consequences to making all variations of parse auto ref for the input range. Should I just go ahead and do it? I'll move the imports inside of the unit test blocks themselves. This is a style choice I've been wondering about. |
…. Moved the std.container import inside the unittest blocks.
Target parse(Target, Source)(ref Source s) | ||
if (isSomeChar!(ElementType!Source) && | ||
Target parse(Target, Source)(auto ref Source s) | ||
if (isInputRange!Source && isSomeChar!(ElementType!Source) && |
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.
ElementType!Source does not require that Source is a range, yet Source has to be a range as a popFront function is required in the body of these parse functions. Thus, isInputRange!Source.
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.
Yah, I agree with the others that auto ref
here does more harm than good. Could you please remove that from all overloads? The changes to the constraints seem legit.
After some consideration, I have taken a different approach to the fix, and now the parse functions should work with any input range, regardless of whether or not the input range is an l-value or r-value. There are some exceptions to this. It will not work with straight input ranges on enum types, bool, or typeof(null), as these variations of parse require slice operations. I don't think I'm clever enough to fix this. parse with other types ought to work, like numbers, dynamic/static arrays of numbers, and associative arrays (like int[string]). |
Strange, I thought I had commented on this before. Anyways: I don't think parse should accept R-values. While it might look convenient on paper, the modifications that parse deals to For example: If the user does not want to validate the output of parse, then that's the user's problem, but the interface of parse itself should not promote it. Further more, it can be bug prone if the user does think his range gets consumed, eg: while (!s.null)
writeln(s[].parse!int); That little inconspicuous FYI, I had submitted the same thing for |
It would be incredibly harmful IMHO for |
I'll just close this down for doing more harm than good. |
This address an issue with parse functions for numeric values not supporting r-value ranges. By fixing this, it makes it possible to use parse on a slice of an std.container Array.