Trouble using 'sort'

Bahman Movaqar via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Mon Jul 25 22:05:50 PDT 2016


I have a range which is the result of a couple of chained range
operations, and each element is:

    Tuple!(string, "product", double, "price")

Now I'd like to sort the range by "price" using:

    sort!((pp1, pp2) => cmp(pp1.price,  pp2.price) > 0)(theRange)

But I get a compile time error:

source/services.d(166,63): Error: template std.algorithm.sorting.sort
cannot deduce function from argument types !((pp1, pp2) =>
cmp(pp1.price, pp2.price) > 0)(MapResult!(__lambda5, Result)),
candidates are:
/home/bahman/Programs/D/dmd-2.071.0/linux/bin64/../../src/phobos/std/algorithm/sorting.d(1027,1):
       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)
source/services.d(168,5): Error: var has no effect in expression (theRange)
dmd failed with exit code 1.

And I have no clue what it is complaining about.  I'd really appreciate
any hint/help on this.

Thanks,

-- 
Bahman


More information about the Digitalmars-d-learn mailing list