Why can't static arrays be sorted?
Vladimir Panteleev via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Tue Oct 4 13:06:02 PDT 2016
On Tuesday, 4 October 2016 at 20:05:15 UTC, TheGag96 wrote:
> I was writing some code today and ran into this oddity that I'd
> never come across before:
>
> import std.algorithm : sort;
> int[10] arr = [0, 3, 4, 6, 2, 1, 1, 4, 6, 9];
> thing.sort();
>
> This doesn't compile. Obviously the .sort property works, but
> what about static arrays makes them unable to be sorted by
> std.algorithm.sort? Thanks.
Static arrays in D are value types. Try:
thing[].sort();
This will pass a slice of the array to sort, holding a reference
to the static array's data.
More information about the Digitalmars-d-learn
mailing list