Why can't static arrays be sorted?

TheGag96 via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Wed Oct 5 11:19:27 PDT 2016


On Wednesday, 5 October 2016 at 02:19:13 UTC, Jonathan M Davis 
wrote:
> The problem is that static arrays aren't ranges (calling 
> popFront on them can't work, because their length isn't 
> mutable). However, you can slice a static array to get a 
> dynamic array which _is_ a range. e.g.
>
> thing[].sort();
>
> Just make sure that such a dynamic array does not outlive the 
> static array, or it will refer to invalid memory (which would 
> not be a problem in this case).
>
> - Jonathan M Davis

Ah thanks guys. I think I just got used to thinking arrays would 
always be found to be ranges by the compiler. Good to know!


More information about the Digitalmars-d-learn mailing list