www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [CBug] opCmp and Sort

reply J Anderson <REMOVEanderson badmama.com.au> writes:
I'm just bring this up (again) so I can add it to the Pending Peeves 
list if bigW (or everyone else) agrees.

When sorting you have to use:

class A
{
   int opCmp(Object x)
   {
      A a = (a) x;
      if (a)
         ...
   }
}

The logical solution is:

class A
{
   int opCmp(A x)
   {
      ...
   }
}

Why can't this be so?

-- 
-Anderson: http://badmama.com.au/~anderson/
May 03 2004
next sibling parent J Anderson <REMOVEanderson badmama.com.au> writes:
J Anderson wrote:

 I'm just bring this up (again) so I can add it to the Pending Peeves 
 list if bigW (or everyone else) agrees.
I'll add it to the feature request list if everyone else agrees, if bigW agrees I'll put it in the pending peeves.
 When sorting you have to use:

 class A
 {
   int opCmp(Object x)
   {
      A a = (a) x;
      if (a)
         ...
   }
 }

 The logical solution is:

 class A
 {
   int opCmp(A x)
   {
      ...
   }
 }

 Why can't this be so?
-- -Anderson: http://badmama.com.au/~anderson/
May 03 2004
prev sibling parent reply Stewart Gordon <smjg_1998 yahoo.com> writes:
J Anderson wrote:

 I'm just bring this up (again) so I can add it to the Pending Peeves 
 list if bigW (or everyone else) agrees.
The pending peeves list is free for all to add stuff to. No need for any authoritative or unanimous seconding.
 When sorting you have to use:
 
 class A
 {
   int opCmp(Object x)
<snip>
 
 The logical solution is:
 
 class A
 {
   int opCmp(A x)
<snip> This is another case of the problem that manifests in associative arrays, but I agree it's worth bringing up as a separate issue. Also, it should work with structs rather than having to set up a TypeInfo class. Stewart. -- My e-mail is valid but not my primary mailbox, aside from its being the unfortunate victim of intensive mail-bombing at the moment. Please keep replies on the 'group where everyone may benefit.
May 04 2004
parent reply J Anderson <REMOVEanderson badmama.com.au> writes:
Stewart Gordon wrote:

 J Anderson wrote:

 I'm just bring this up (again) so I can add it to the Pending Peeves 
 list if bigW (or everyone else) agrees.
The pending peeves list is free for all to add stuff to. No need for any authoritative or unanimous seconding.
I was wondering whether is there is a good reason to keep opCmp the way it is. -- -Anderson: http://badmama.com.au/~anderson/
May 04 2004
parent reply Stewart Gordon <smjg_1998 yahoo.com> writes:
J Anderson wrote:

<snip>
 I was wondering whether is there is a good reason to keep opCmp the way 
 it is.
Less than none that I can see. http://www.digitalmars.com/drn-bin/wwwnews?D/26144 We have a simple solution that wouldn't break backward compatibility AFAICS. 1. Fix sort and AAs to work with a self-specific opCmp. 2. Deprecate Object.opCmp. 3. Change AAs so that if the key type has no matching opCmp, or only a deprecated one, it will skip that stage of the lookup. Stewart. -- My e-mail is valid but not my primary mailbox, aside from its being the unfortunate victim of intensive mail-bombing at the moment. Please keep replies on the 'group where everyone may benefit.
May 05 2004
next sibling parent reply J Anderson <REMOVEanderson badmama.com.au> writes:
Stewart Gordon wrote:

 J Anderson wrote:

 <snip>

 I was wondering whether is there is a good reason to keep opCmp the 
 way it is.
Less than none that I can see. http://www.digitalmars.com/drn-bin/wwwnews?D/26144 We have a simple solution that wouldn't break backward compatibility AFAICS. 1. Fix sort and AAs to work with a self-specific opCmp. 2. Deprecate Object.opCmp.
 3. Change AAs so that if the key type has no matching opCmp, or only a 
 deprecated one, it will skip that stage of the lookup.

 Stewart.
I guess the default one could be useful for associative arrays implementations who use a binary sort (ie stl's maps). -- -Anderson: http://badmama.com.au/~anderson/
May 05 2004
parent reply Stewart Gordon <smjg_1998 yahoo.com> writes:
J Anderson wrote:

<snip>
 I guess the default one could be useful for associative arrays 
 implementations who use a binary sort
They already won't work if the type has no ordering.
 (ie stl's maps).
I somehow doubt that STL is the only one. Stewart. -- My e-mail is valid but not my primary mailbox, aside from its being the unfortunate victim of intensive mail-bombing at the moment. Please keep replies on the 'group where everyone may benefit.
May 05 2004
parent J Anderson <REMOVEanderson badmama.com.au> writes:
Stewart Gordon wrote:

 J Anderson wrote:

 <snip>

 I guess the default one could be useful for associative arrays 
 implementations who use a binary sort
They already won't work if the type has no ordering.
Oh. Your right then.
 (ie stl's maps).
I somehow doubt that STL is the only one. Stewart.
-- -Anderson: http://badmama.com.au/~anderson/
May 05 2004
prev sibling parent "Ivan Senji" <ivan.senji public.srce.hr> writes:
"Stewart Gordon" <smjg_1998 yahoo.com> wrote in message
news:c7ac8o$d36$1 digitaldaemon.com...
 J Anderson wrote:

 <snip>
 I was wondering whether is there is a good reason to keep opCmp the way
 it is.
Less than none that I can see. http://www.digitalmars.com/drn-bin/wwwnews?D/26144 We have a simple solution that wouldn't break backward compatibility AFAICS. 1. Fix sort and AAs to work with a self-specific opCmp. 2. Deprecate Object.opCmp.
I would also vote for deprecating Object.opEquals because it is totally unneaded and a potential cause of bugs.
 3. Change AAs so that if the key type has no matching opCmp, or only a
 deprecated one, it will skip that stage of the lookup.

 Stewart.

 --
 My e-mail is valid but not my primary mailbox, aside from its being the
 unfortunate victim of intensive mail-bombing at the moment.  Please keep
 replies on the 'group where everyone may benefit.
May 05 2004