Re: Trouble using 'sort'

2016-07-26 Thread Bahman Movaqar via Digitalmars-d-learn
On 07/26/2016 11:42 AM, drug wrote: > Another option is `makeIndex` (std.algorithm.sorting) and then sorting > of that index. That's an interesting option; at least I don't have to touch the range. Thanks. -- Bahman

Re: Trouble using 'sort'

2016-07-26 Thread Bahman Movaqar via Digitalmars-d-learn
On 07/26/2016 10:41 AM, Jonathan M Davis via Digitalmars-d-learn wrote: >> So it may be something about what kind of range I'm passing to `sort`. >> Am I right? > > sort requires a random access range. Without knowing exactly which > algorithms your using, I can't say for sure that that's the

Re: Trouble using 'sort'

2016-07-26 Thread drug via Digitalmars-d-learn
26.07.2016 09:11, Jonathan M Davis via Digitalmars-d-learn пишет: It's frequently the case that if you want to sort a range, you have to call array() on it to convert it to an array, and then you can sort the array. - Jonathan M Davis Another option is `makeIndex` (std.algorithm.sorting) and

Re: Trouble using 'sort'

2016-07-26 Thread Jonathan M Davis via Digitalmars-d-learn
On Tuesday, July 26, 2016 10:11:43 Bahman Movaqar via Digitalmars-d-learn wrote: > On 07/26/2016 09:35 AM, Bahman Movaqar wrote: > > I have a range which is the result of a couple of chained range > > > > operations, and each element is: > > Tuple!(string, "product", double, "price") > > > >

Re: Trouble using 'sort'

2016-07-25 Thread Bahman Movaqar via Digitalmars-d-learn
On 07/26/2016 10:11 AM, Bahman Movaqar wrote: > Alright...further experiments. The following works: > > sort!((pp1, pp2) => cmp(pp1.price, pp2.price) > 0)(theRange) > > So it may be something about what kind of range I'm passing to `sort`. > Am I right? > I meant sort!((pp1, pp2) =>

Re: Trouble using 'sort'

2016-07-25 Thread Bahman Movaqar via Digitalmars-d-learn
On 07/26/2016 09:35 AM, Bahman Movaqar wrote: > 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,

Trouble using 'sort'

2016-07-25 Thread Bahman Movaqar via Digitalmars-d-learn
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: