-
-
Notifications
You must be signed in to change notification settings - Fork 693
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
[trivial] std.conv: Don't allow to!T() in constraint #4898
Conversation
Also avoid highlighting 'to' unnecessarily.
isStaticArray!T already checks !isAggregateType!T.
|
T to(A...)(A args) | ||
if (!isRawStaticArray!A) | ||
if (A.length > 0 && !isStaticArray!(A[0])) |
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.
Ideally we should have 2 overloads instead of just using args
here, I can do that after this pull is merged.
enum isRawStaticArray = | ||
A.length == 0 && | ||
isStaticArray!T && | ||
!is(T == 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.
These static tests are for alias <member that's a static array> this
, can they really be suppressed ?
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.
Yes, please see the full commit message.
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.
OK.
@@ -230,7 +221,7 @@ template to(T) | |||
* When converting strings _to numeric types, note that the D hexadecimal and binary | |||
* literals are not handled. Neither the prefixes that indicate the base, nor the | |||
* horizontal bar used _to separate groups of digits are recognized. This also | |||
* applies to the suffixes that indicate the type. | |||
* applies _to the suffixes that indicate the type. |
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.
don't merge two fixes. the to
-> _to
is another issue. If your PR gets merged for the code and reverted because of regression than the fix for the DDOC will also be lost.
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.
Ideally, yes. But I think this is what most people do for very minor changes, otherwise we'd get tons of PRs.
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 hit a wall here. Don't merge two things in one PR. End of story. Waiting for you to amend.
Open another PR for the ddoc.
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.
we'd get tons of PRs.
That's not a problem, annotate it with [TRIVIAL, DDOC] and it'll be merged quickly.
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.
Removed doc changes.
@bbasile Merge please? |
@@ -178,14 +167,14 @@ $(I UnsignedInteger): | |||
template to(T) | |||
{ | |||
T to(A...)(A args) | |||
if (!isRawStaticArray!A) | |||
if (A.length > 0 && !isStaticArray!(A[0])) |
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.
I believe the previous constraint is equivalent to this instead:
if(A.length > 0 || !isStaticArray!(A[0]))
The calls it allows vs. your constraint, I'm not sure are valid. But this is a difference.
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.
Boy, that's not a very good constraint :)
This is better
if(A.length != 1 || !isStaticArray!(A[0]))
LGTM, just fix the constraint, and I will merge. |
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.
Nevermind, I forgot I can just fix it myself :)
Auto-merge toggled on |
@schveiguy: You have undone the fix for the issue.
I think we can use specialization to achieve what you want neatly:
Note: my original code was actually correct because for more than one argument, the only options are for the first argument to pass |
I thought the issue was that the internal isRawStaticArray appears in the error message? |
to!string() shouldn't compile, and I don't think it did with the original code, right? So why change the constraint? |
You're right it doesn't successfully compile, but the constraint should prevent internal errors with |
BTW Thanks for reviewing, the original issue is much better after this merge ;-) |
Also document
to
template functions within parentto
template.