Thread overview | |||||
---|---|---|---|---|---|
|
June 27, 2015 aa.byKeyValue().sort!"a.key < b.key" | ||||
---|---|---|---|---|
| ||||
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? |
June 27, 2015 Re: aa.byKeyValue().sort!"a.key < b.key" | ||||
---|---|---|---|---|
| ||||
Posted in reply to Nicholas Wilson | On Sat, Jun 27, 2015 at 12:22:06PM +0000, Nicholas Wilson via Digitalmars-d-learn wrote: > How do I iterate through an AA sorted by key? > > I am unable to .dup the aa.byKeyValue(). Because it is a range, not an array. To turn it into an array, write: aa.byKeyValue().array.sort!"a.key < b.key" T -- Three out of two people have difficulties with fractions. -- Dirk Eddelbuettel |
June 27, 2015 Re: aa.byKeyValue().sort!"a.key < b.key" | ||||
---|---|---|---|---|
| ||||
Posted in reply to H. S. Teoh | On Saturday, 27 June 2015 at 12:27:59 UTC, H. S. Teoh wrote:
> On Sat, Jun 27, 2015 at 12:22:06PM +0000, Nicholas Wilson via Digitalmars-d-learn wrote:
>> How do I iterate through an AA sorted by key?
>>
>> I am unable to .dup the aa.byKeyValue().
>
> Because it is a range, not an array.
>
> To turn it into an array, write:
>
> aa.byKeyValue().array.sort!"a.key < b.key"
>
>
> T
Derp.
Thankyou!
|
Copyright © 1999-2021 by the D Language Foundation