digitalmars.D.announce - [Blog post] Operator overloading for structs in D
- Minas Mina (4/4) Jun 02 2016 I have written a blog post about operator overloading for structs.
- Steven Schveighoffer (16/20) Jun 02 2016 Cool. You missed one very significant thing. That is using mixins to
- Minas Mina (4/22) Jun 02 2016 Thanks for the feedback! I will update the post tomorrow or on
- Walter Bright (5/9) Jun 02 2016 Things usually go better on Reddit if you post as the first comment a su...
- Minas Mina (3/16) Jun 02 2016 What can I do about this?
- Mike Parker (3/6) Jun 03 2016 Announce the post here and ask someone to post it to reddit for
I have written a blog post about operator overloading for structs. You can find it here: https://www.reddit.com/r/programming/comments/4m8mgr/operator_overloading_for_structs_in_d/ Comments and suggestions are appreciated.
Jun 02 2016
On 6/2/16 2:34 PM, Minas Mina wrote:I have written a blog post about operator overloading for structs. You can find it here: https://www.reddit.com/r/programming/comments/4m8mgr/operator_overloading_for_structs_in_d/ Comments and suggestions are appreciated.Cool. You missed one very significant thing. That is using mixins to take advantage of the operator string. For example, opOpAssign can be done in one step: ref Rational opOpAssign(string op)(auto ref Rational r) if(op == "+" || op == "-" || op == "/" || op == "*") { mixin("auto tmp = this " ~ op ~ " r;"); _n = tmp.n; _d = tmp.d; return this; } This is the whole reason, BTW, that operator overloads were changed from the original D1 style versions. Some more examples of your Rational type in action would be good too. -Steve
Jun 02 2016
On Thursday, 2 June 2016 at 18:55:36 UTC, Steven Schveighoffer wrote:On 6/2/16 2:34 PM, Minas Mina wrote:Thanks for the feedback! I will update the post tomorrow or on Saturday.[...]Cool. You missed one very significant thing. That is using mixins to take advantage of the operator string. For example, opOpAssign can be done in one step: ref Rational opOpAssign(string op)(auto ref Rational r) if(op == "+" || op == "-" || op == "/" || op == "*") { mixin("auto tmp = this " ~ op ~ " r;"); _n = tmp.n; _d = tmp.d; return this; } This is the whole reason, BTW, that operator overloads were changed from the original D1 style versions. Some more examples of your Rational type in action would be good too. -Steve
Jun 02 2016
On 6/2/2016 11:34 AM, Minas Mina wrote:I have written a blog post about operator overloading for structs. You can find it here: https://www.reddit.com/r/programming/comments/4m8mgr/operator_overloading_for_structs_in_d/ Comments and suggestions are appreciated.Things usually go better on Reddit if you post as the first comment a summary of what the article is about. Also, if you post your own articles, Reddit is likely to put you on their auto-ban list :-(
Jun 02 2016
On Thursday, 2 June 2016 at 20:53:18 UTC, Walter Bright wrote:On 6/2/2016 11:34 AM, Minas Mina wrote:I'll do it in future posts then :)I have written a blog post about operator overloading for structs. You can find it here: https://www.reddit.com/r/programming/comments/4m8mgr/operator_overloading_for_structs_in_d/ Comments and suggestions are appreciated.Things usually go better on Reddit if you post as the first comment a summary of what the article is about.Also, if you post your own articles, Reddit is likely to put you on their auto-ban list :-(What can I do about this?
Jun 02 2016
On Friday, 3 June 2016 at 06:47:40 UTC, Minas Mina wrote:Announce the post here and ask someone to post it to reddit for you.Also, if you post your own articles, Reddit is likely to put you on their auto-ban list :-(What can I do about this?
Jun 03 2016