Re: Comparison operator overloading

2015-12-07 Thread Mike Parker via Digitalmars-d-learn
On Monday, 7 December 2015 at 11:49:51 UTC, Dominikus Dittes Scherkl wrote: On Sunday, 6 December 2015 at 15:01:08 UTC, cym13 wrote: Don't use opCmp, all binary operators should be overriden using opBinary. For more information I recommend this page

Re: Comparison operator overloading

2015-12-07 Thread Dominikus Dittes Scherkl via Digitalmars-d-learn
On Monday, 7 December 2015 at 13:31:52 UTC, Mike Parker wrote: On Monday, 7 December 2015 at 11:49:51 UTC, Dominikus Dittes Scherkl wrote: On the other hand the chapter also states that opCmp() should always return "int" - which is a bad idea if you e.g. want to provide a "NaN" value in your

Re: Comparison operator overloading

2015-12-07 Thread Dominikus Dittes Scherkl via Digitalmars-d-learn
On Sunday, 6 December 2015 at 15:01:08 UTC, cym13 wrote: Don't use opCmp, all binary operators should be overriden using opBinary. For more information I recommend this page http://ddili.org/ders/d.en/operator_overloading.html Why should we don't use opCmp() ? I can't see any recommendation

Re: Comparison operator overloading

2015-12-07 Thread Márcio Martins via Digitalmars-d-learn
On Monday, 7 December 2015 at 00:43:50 UTC, Ali Çehreli wrote: On 12/06/2015 06:41 AM, Márcio Martins wrote: > auto m = (a > b) * a + 15; > auto c = a.choose(a > b)^^2; What do those operations do? Are you thinking of a special meaning for '>', perhaps common in numerical computations, which

Re: Comparison operator overloading

2015-12-07 Thread Anonymous via Digitalmars-d-learn
On Monday, 7 December 2015 at 17:18:20 UTC, Dominikus Dittes Scherkl wrote: Hmm. But it works just fine! It overloads also the special floatingpoint operators <> !<> !<= and so on. Those are deprecated: http://dlang.org/deprecate.html#Floating%20point%20NCEG%20operators And how else could I

Comparison operator overloading

2015-12-06 Thread Márcio Martins via Digitalmars-d-learn
I am writing a generic numerical array struct, and I can't find a way to do element-wise comparison operators. What I had envisioned was something like the following, assuming a, b, c and m are array-like, and all operations return arrays. auto m = (a > b) * a + 15; auto c = a.choose(a >

Re: Comparison operator overloading

2015-12-06 Thread cym13 via Digitalmars-d-learn
On Sunday, 6 December 2015 at 14:41:01 UTC, Márcio Martins wrote: I am writing a generic numerical array struct, and I can't find a way to do element-wise comparison operators. What I had envisioned was something like the following, assuming a, b, c and m are array-like, and all operations

Re: Comparison operator overloading

2015-12-06 Thread Ali Çehreli via Digitalmars-d-learn
On 12/06/2015 06:41 AM, Márcio Martins wrote: > auto m = (a > b) * a + 15; > auto c = a.choose(a > b)^^2; What do those operations do? Are you thinking of a special meaning for '>', perhaps common in numerical computations, which I'm not familiar with? If I understand correctly, 'a > b' in