Sort bug / strangeness

Danny Arends Danny.Arends at
Fri Oct 1 18:30:48 UTC 2021

On Friday, 1 October 2021 at 17:53:24 UTC, Steven Schveighoffer 
> I think your struct is different than this, because this only 
> happens if aliasing is inside the struct being sorted (i.e. it 
> has pointers). Your presented struct doesn't have pointers, and 
> the code you linked to is completely parameterized on the 
> struct type.
> If it does have pointers, you are not allowed to swap the 
> values if either points to each other (or themselves).

Thanks Steve for saving Friday,

The struct has indeed a parent pointer, It's a pretty big struct 
so just posted the excerpt (sorry). So that's the cause then.

So how to sort this N[] object by f() then ?

The pointer is only used to be traversed back after the search 
has finished. Is there a sort() algorithm that avoids swapping 
the items themselves and e.g. just returns the indexes so I can 
reorder the original array myself ?


More information about the Digitalmars-d-learn mailing list