-
-
Notifications
You must be signed in to change notification settings - Fork 706
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
Issue 14382 - converting old D1 operator overloading style to new D2 style #3130
Conversation
|
Previous discussions for reference: |
| // ///ditto | ||
| // VariantN opShr_r(T)(T lhs) | ||
| // { | ||
| // return VariantN(lhs).opLogic!(VariantN, ">>")(this); | ||
| // } | ||
| ///ditto | ||
| VariantN opUShr(T)(T rhs) { return opLogic!(T, ">>>")(rhs); } | ||
| VariantN opBinary(string op : ">>>", T)(T rhs) { return opLogic!(T, ">>>")(rhs); } |
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.
All these functions are nearly identical. The whole point of having the template was so you can easily implement multiple operators with one set of code. For example:
VariantN opBinary(string op, T)(T rhs) if (op == "+" || op == "-" || op = "*" || op = "/")
{
return opArithmetic!(T, op)(rhs);
}In fact, I'd say get rid of opArithmetic and opLogic, and just move the implementations into an appropriate opBinary
|
This makes the code less readable. The old operator overloading methods aren't deprecated. The new methods are more powerful, and that power is wasted in 100% of these cases. |
What about with my suggested updates?
The old operator overloading methods are not documented (I will correct this), but should not be used in Phobos IMO. If there was ever a type that could use template + mixin opBinary, it would be Variant. |
|
Seems useful if @schveiguy suggestions are followed through. @schuetzm any plans to update this? |
|
This is ketmar's patch, I'm going to ask him. Maybe I'll also find some time to do it myself. |
|
@schuetzm, any news on this? |
|
ping |
Patches by ketmar: https://issues.dlang.org/show_bug.cgi?id=14382