Why can't static arrays be sorted?
pineapple via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Wed Oct 5 12:22:03 PDT 2016
On Wednesday, 5 October 2016 at 18:19:27 UTC, TheGag96 wrote:
> 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!
Would just like to point out that this is design weirdness on
Phobos' part - the library I've been writing does not have this
problem.
More information about the Digitalmars-d-learn
mailing list