March 07, 2017
On Tuesday, 7 March 2017 at 19:40:53 UTC, Andrei Alexandrescu wrote:
> On 03/07/2017 12:54 PM, H. S. Teoh via Digitalmars-d wrote:
>> (1) I may be remembering wrong, but I thought structs had always been
>> intended to be compared field-wise?  I remember when working on AA's
>> that the compiler would emit a default implementation of opEquals that
>> did member-wise comparisons. I had always assumed that something
>> similar was done with inequalities... or was that just unfounded
>> extrapolation?
>
> We currently do memcmp.
>
> Equality by memberwise comparison is almost always meaningful; ordering by lexicographic comparison of members is not.
>
>
> Andrei

We should deprecate that array comparison behavior immediately.
It should not break much code, otherwise the issue would have popped up before.
March 07, 2017
On Tue, Mar 07, 2017 at 07:53:37PM +0000, Stefan Koch via Digitalmars-d wrote:
> On Tuesday, 7 March 2017 at 19:40:53 UTC, Andrei Alexandrescu wrote:
> > On 03/07/2017 12:54 PM, H. S. Teoh via Digitalmars-d wrote:
> > > (1) I may be remembering wrong, but I thought structs had always been intended to be compared field-wise?  I remember when working on AA's that the compiler would emit a default implementation of opEquals that did member-wise comparisons. I had always assumed that something similar was done with inequalities... or was that just unfounded extrapolation?
> > 
> > We currently do memcmp.
> > 
> > Equality by memberwise comparison is almost always meaningful; ordering by lexicographic comparison of members is not.
> > 
> > 
> > Andrei
> 
> We should deprecate that array comparison behavior immediately.  It should not break much code, otherwise the issue would have popped up before.

Unfortunately, because strings are arrays, deprecating array comparisons *will* break a *lot* of code.

I'm all for deprecating comparisons between arrays of structs, though. The best way to do this is to deprecate implicit struct comparisons (the user has to define opCmp if he wants to compare structs).


T

-- 
What doesn't kill me makes me stranger.
March 07, 2017
On 03/07/2017 03:49 PM, H. S. Teoh via Digitalmars-d wrote:
> Unfortunately, because strings are arrays, deprecating array comparisons
> *will* break a *lot* of code.

Misunderstanding, string comparisons are legit because character comparisons are legit. This is about deprecating array comparisons that don't have a corresponding element comparison. -- Andrei
1 2
Next ›   Last »