std.algorithm range violation
monarch_dodra via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Wed May 28 11:04:08 PDT 2014
On Wednesday, 28 May 2014 at 17:39:15 UTC, monarch_dodra wrote:
> On Wednesday, 28 May 2014 at 11:40:05 UTC, Wanderer wrote:
>> Sorry about typo, I meant
>>
>> providor_symbol_map.sort!((x,y)=>{x.value.length>y.value.length})
>>
>> above.
>
> providor_symbol_map is an Associative Array, so you can't sort
> that. *Usually*, you want to do what the OP did, which is to
> get the keys, and sort them, but leave the AA unchanged. EG:
>
> Val[Key] myAA;
> Key[] mySortedKeys = myAA.keys.sort!((x, y)=> compare(myAA[x],
> myAA[y]))()
>
> //Print values in incremented order:
> foreach(key; mySortedKeys)
> writefln("%s: %s", key, myAA[key]);
I case this was not clear "compare" is an function you should
replace with your own. It should simply define strict ordering of
x and y. "<" is one such function.
More information about the Digitalmars-d-learn
mailing list