[Issue 1861] make .sort not fail if opCmp takes ref param

d-bugmail at puremagic.com d-bugmail at puremagic.com
Fri Feb 22 14:19:28 PST 2008


http://d.puremagic.com/issues/show_bug.cgi?id=1861


wbaxter at gmail.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Severity|major                       |enhancement
             Status|RESOLVED                    |REOPENED
         Resolution|INVALID                     |
            Summary|.sort fails if opCmp takes  |make .sort not fail if opCmp
                   |ref param                   |takes ref param




------- Comment #3 from wbaxter at gmail.com  2008-02-22 16:19 -------
Ok, the documentation says either use Type or Type* for opCmp.  The .sort
property does in fact work with either.  The problem with just using Type* is
that it isn't called for regular struct comparisons like 
   Type a,b; 
   a<b

The problem with using just Type is that it makes sorting unnecessarily slow,
since value arguments will have to be copied for every call of the comparison
function.

It makes no sense not to allow ref.  This is exactly the kind of thing ref was
meant for, where you want value semantics, but only want to pass a pointer
around.

Interestingly, if you provide BOTH a Type* and a ref Type version of opCmp,
then regular comparisons will use the ref version, and .sort will use the
pointer version.  

But it would be nicer if ref just worked.  I find it very surprising that it
doesn't, and until it does I would suggest that the documentation be changed to
say in very big bold letters that EVEN THOUGH REF MAY APPEAR TO WORK FOR SMALL
TEST CASES IT IS NOT SUPPORTED AND WILL FAIL IF YOU TRY TO .sort.


-- 



More information about the Digitalmars-d-bugs mailing list