aa.byKeyValue().sort!"a.key < b.key"

Nicholas Wilson via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Sat Jun 27 05:22:06 PDT 2015


How do I iterate through an AA sorted by key?

I am unable to .dup the aa.byKeyValue().

I have tried both
foreach(e; aa.byKeyValue().sort!"a.key < b.key")
{
     //... use e. key && e.value
}

and

foreach(k,v; aa.byKeyValue().sort!"a.key < b.key")
{

}

i get :
template std.algorithm.sorting.sort cannot deduce function from 
argument types !("a.key < b.key")(Result), candidates are:
std/algorithm/sorting.d(875):        
std.algorithm.sorting.sort(alias less = "a < b", SwapStrategy ss 
= SwapStrategy.unstable, Range)(Range r) if ((ss == 
SwapStrategy.unstable && (hasSwappableElements!Range || 
hasAssignableElements!Range) || ss != SwapStrategy.unstable && 
hasAssignableElements!Range) && isRandomAccessRange!Range && 
hasSlicing!Range && hasLength!Range)

any clues?


More information about the Digitalmars-d-learn mailing list