-
-
Notifications
You must be signed in to change notification settings - Fork 740
Implement issue# 10314 (add std.traits.signed). #1341
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
else | ||
{ | ||
static assert(T.min != 0, "Bug in either signed or isIntegral"); | ||
return cast(Unqual!T) x; |
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.
This line is dead code. It should be removed.
edit:
Nevermind, I read wrong.
The documentation does not indicate that it removes Integral types are value types with no indirection, so it's not a huge issue, but considering that |
UnsignedTypeOf? |
I see that we have |
On the whole, I wouldn't expect it to be a big deal to make |
Yeah, I understand the concern. Further, I'd argue that It would be most intuitive if:
Meant In this interpretation, the behaviour is simply changed to match both the documentation and similar interfaces in the module. |
I think we're stuck with making it remove qualifiers. @jmdavis could you please add that info to the docs with this diff? One question that comes to mind is moving |
If we actually go through the trouble of moving them, then it would be better to also take the opportunity to give them the "correct" semantic. Simply going through the effort of moving them, yet doing only half the job seems (sorry) stupid to me. My stance would be that the current implementation is just bugged, and should simply be fixed with no questions asked. If we move it, then I think it should be put on a deprecation path. Having undocumented aliases in phobos doesn't help anyone. Either we move it for reals, or we don't do anything. |
s/stupid/odd/ There is reason, unexpectedly :o). It's one thing to have an alias to the same name in a different module; defining distinct
I don't think it's bugged. It has a spec and it implements it. People can easily add qualifiers on the receiver side. Is a qualifier-preserving definition better? Most likely. Is this a disaster? I don't think so.
OK. |
Maybe not bugged, but what it definitely has is lack of spec. I guess the implementation was free to be implemented around the hole, but at the same time, the user shouldn't rely on something not specified in the spec.
I think that does make a good point actually. Combining both auto s = signed(u); //not qualified
Signed!U s = signed(u); //same qualification
immutbale s = signed(u); //totally qualified So with proper documentation and rationale, I think keeping it as is should work OK. |
Okay. I updated the documentation and included an example of how to use |
*/ | ||
auto signed(T)(T x) if (isIntegral!T) | ||
{ | ||
static if (is(Unqual!T == ubyte )) return cast(byte ) x; |
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.
Can't this whole static if/else chain be replaced by return cast(SignedTypeOf!T)x;
?
I just updated it so that it takes advantage of |
So... No use beating around the bush here I say? We either keep The fact that nobody even noticed that Let's decide which we do... I'm in favor of putting these in |
I'd say move them and leave undocumented aliases in std.traits. |
Okay. I moved |
(e.g from $(D int) to $(D long)). | ||
|
||
Note that the result is always mutable even if the original type was const | ||
or immutable. In order to retain the constness, use $(LREF Unsigned). |
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.
XREF now though. I think this is the correct syntax?
$(XREF traits,Unsigned)
ditto in signed
This moves std.traits.unsigned to std.conv and adds std.conv.signed, since for some reason, we have std.traits.unsigned but do not have std.traits.signed.
Okay, I fixed the docs. |
Anything left on this? |
I have nothing to add. LGTM. |
Ping? |
LGTM. |
Implement issue# 10314 (add std.traits.signed).
This adds std.traits.signed, since for some reason, we have
std.traits.unsigned but do not have std.traits.signed.