November 15, 2014 Re: Functional Sort | ||||
---|---|---|---|---|
| ||||
Posted in reply to Meta | On Saturday, 15 November 2014 at 08:52:45 UTC, Meta wrote:
> On Saturday, 15 November 2014 at 03:47:25 UTC, Steven Schveighoffer wrote:
>> err... this isn't what you want. That will sort the range, and then make a copy of the sorted range as an array.
>
> Yes, I didn't see the the second constraint to not sort the original range.
>
> Sort before .array -> original will be sorted.
>
> Sort after .array -> original will not be sorted.
BTW: When I uncomment line
/* assert(x.sorted == y); */
in string unittest it errors as
sort_ex.d(160,5): Error: can only sort a mutable array
sort_ex.d(178,13): Error: template instance sort_ex.sorted!string error instantiating
What's wrong with my isArray-overload of sorted?
|
November 15, 2014 Re: Functional Sort | ||||
---|---|---|---|---|
| ||||
Posted in reply to Nordlöw | On Saturday, 15 November 2014 at 14:34:07 UTC, Nordlöw wrote:
> What's wrong with my isArray-overload of sorted?
I solved it by replacing
R s = r.dup;
with
auto s = r.dup;
As a follow up I know wonder if it is ok for isArray-overload of sorted() to have return type ubyte[] if input is a string?
I wonder because x.array.sort has type
dchar[]
when x is a string.
|
Copyright © 1999-2021 by the D Language Foundation