Access Violation in callback from sort

Stefan stefan.schuerger at gmx.de
Thu Mar 21 13:02:38 PDT 2013


On Wednesday, 2 May 2012 at 15:27:58 UTC, Jabb wrote:

> import std.algorithm;
> void main() {
> 	uint[string] counts = [ "a":4, "b":5, "c":3, "d":1 ];
> 	string[] keys = counts.keys;
>
> 	sort!((a, b) { return counts[a] > counts[b]; })(keys);
> }

Did you try
string[] keys = counts.keys.dup;
?

Sometimes you get weird aliasing issues, as the sort! template
modifies the original array.


More information about the Digitalmars-d-learn mailing list