Ordering comparisons

H. S. Teoh via Digitalmars-d digitalmars-d at puremagic.com
Tue Mar 7 12:49:19 PST 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.


More information about the Digitalmars-d mailing list