www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - inout in struct opCmp does not sort

reply Nick <Nick_member pathlink.com> writes:
The following example gives the wrong result:
























The output becomes 'sorted' in the same way as when opCmp is not present at all.

However, if the 'inout' is removed from opCmp, it works as expected. I use inout
on large structs to avoid passing huge amounts of data on the stack, but I'm not
sure if this is the 'correct' thing to do...

Note that explicit comparison, eg. l[2] <= l[3], works correctly both with and
without the 'inout' present.

Nick
Jul 07 2005
parent "Walter" <newshound digitalmars.com> writes:
"Nick" <Nick_member pathlink.com> wrote in message
news:daitbq$tia$1 digitaldaemon.com...
 The following example gives the wrong result:
 [...]

rewrite that line as: int opCmp(A* a) { return i - a.i; } and you'll get the behavior you're looking for. The sorter looks for either an in A parameter or an: in A* parameter for the opCmp.
Jul 08 2005