Access Violation in callback from sort

Ali Çehreli acehreli at yahoo.com
Thu Mar 21 16:44:07 PDT 2013


On 03/21/2013 01:02 PM, Stefan wrote:
 > 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;
 > ?

That should be ok. Unlike .byKey, .keys is eager; all of the keys are in 
the returned slice by the time it returns.

Ali



More information about the Digitalmars-d-learn mailing list