[Issue 1339] Invariant/const-ness is broken by built-in array properties

d-bugmail at puremagic.com d-bugmail at puremagic.com
Thu Feb 19 01:41:15 PST 2009


http://d.puremagic.com/issues/show_bug.cgi?id=1339





------- Comment #5 from smjg at iname.com  2009-02-19 03:41 -------
(In reply to comment #4)
> (In reply to comment #3)
>> It reallocated array on increasing length. Seems valid.

What did - the testcase here with checking added, the testcase at bug 2093 or
your own?  With which DMD version?

> Problem is that sort and reverse work in-place, thus modifying immutable
> variable. It should either not compile /or/ allocate a copy. I don't like the
> hidden allocations, so this should be just disallowed, imo.

Indeed, to either modify in-place or reallocate depending on constancy status
would be a confusing inconsistency.  They should be distinct operations. 
Indeed, you can already do a reallocating sort or reverse by doing

    int[] sorted = x.dup.sort;
    invariant(int)[] = assumeUnique(x.dup.reverse);

so it would be a question of whether it's worth creating syntactic sugar for
this.


-- 



More information about the Digitalmars-d-bugs mailing list