digitalmars.D - Overloading comparison and Equality Operators
- d coder (8/8) Sep 06 2011 Greetings
- Timon Gehr (3/11) Sep 06 2011 That is currently impossible. =/
- Brad Roberts (6/20) Sep 06 2011 Normally I try to avoid nit picking phrasing in public forums, but in
- Timon Gehr (4/22) Sep 07 2011 I never said there was. I wanted to express I wish there was.
- Trass3r (3/7) Sep 06 2011 What are you trying to do?
- Timon Gehr (3/10) Sep 06 2011 Which is a fancy way of returning an int. Probably he wants to implement...
Greetings It seems D assumes that these operators should return a bool value. For example=C2=A0a < b is re-written as=C2=A0a.=E2=80=8BopCmp(b) < 0. In my application, I wanted to overload comparison and equality operators to return user defined values. Is that possible in D? If so how? Regards - Puneet
Sep 06 2011
On 09/06/2011 04:13 PM, d coder wrote:Greetings It seems D assumes that these operators should return a bool value. For example a< b is re-written as a.opCmp(b)< 0. In my application, I wanted to overload comparison and equality operators to return user defined values. Is that possible in D? If so how? Regards - PuneetThat is currently impossible. =/ You'll have to use named member functions, eg. less, greater and equal.
Sep 06 2011
On Tuesday, September 06, 2011 9:09:06 AM, Timon Gehr wrote:On 09/06/2011 04:13 PM, d coder wrote:Normally I try to avoid nit picking phrasing in public forums, but in this case it's important. It's not just 'currently' impossible, it's by design with no intention to change. Later, BradGreetings It seems D assumes that these operators should return a bool value. For example a< b is re-written as a.opCmp(b)< 0. In my application, I wanted to overload comparison and equality operators to return user defined values. Is that possible in D? If so how? Regards - PuneetThat is currently impossible. =/ You'll have to use named member functions, eg. less, greater and equal.
Sep 06 2011
On 09/07/2011 05:28 AM, Brad Roberts wrote:On Tuesday, September 06, 2011 9:09:06 AM, Timon Gehr wrote:not 'just' currently, but I never said 'just'. ;)On 09/06/2011 04:13 PM, d coder wrote:Normally I try to avoid nit picking phrasing in public forums, but in this case it's important. It's not just 'currently' impossible,Greetings It seems D assumes that these operators should return a bool value. For example a< b is re-written as a.opCmp(b)< 0. In my application, I wanted to overload comparison and equality operators to return user defined values. Is that possible in D? If so how? Regards - PuneetThat is currently impossible. =/ You'll have to use named member functions, eg. less, greater and equal.it's by design with no intention to change.I never said there was. I wanted to express I wish there was. Timon
Sep 07 2011
For example a < b is re-written as a.=E2=80=8BopCmp(b) < 0. In my application, I wanted to overload comparison and equality operators to return user defined values. Is that possible in D? If so how?What are you trying to do? In the end opCmp can return any value or object that works in the = rewritten case 'a.opCmp(b) < 0'.
Sep 06 2011
On 09/06/2011 07:21 PM, Trass3r wrote:Which is a fancy way of returning an int. Probably he wants to implement expression templates.For example a < b is re-written as a.opCmp(b) < 0. In my application, I wanted to overload comparison and equality operators to return user defined values. Is that possible in D? If so how?What are you trying to do? In the end opCmp can return any value or object that works in the rewritten case 'a.opCmp(b) < 0'.
Sep 06 2011
Actually not expression templates. I am porting a BDD (Binary decision diagrams) library from C++ to D. The comparison operators are just implemented as relations that return another BDD. A BDD would then evaluate to 0 or 1 depending on many other factors and other BDDs. A BDD actually represents a node on an acyclic graph. Being able to overload comparison operators more generically would have helped. For now I am using named functions as Timon suggested. Regards - PuneetWhich is a fancy way of returning an int. Probably he wants to implement expression templates.For example a < b is re-written as a.opCmp(b) < 0. In my application, I wanted to overload comparison and equality operators to return user defined values. Is that possible in D? If so how?What are you trying to do? In the end opCmp can return any value or object that works in the rewritten case 'a.opCmp(b) < 0'.
Sep 06 2011
Actually not expression templates. I am porting a BDD (Binary decision diagrams) library from C++ to D. The comparison operators are just implemented as relations that return another BDD. A BDD would then evaluate to 0 or 1 depending on many other factors and other BDDs. A BDD actually represents a node on an acyclic graph.Excuse my poor knowledge of expression templates. It seems I am doing something similar to expression templates, but not at meta-programming level. Regards - Puneet
Sep 06 2011