Why string alias is invariant ?

Steven Schveighoffer schveiguy at yahoo.com
Thu Jan 31 11:06:30 PST 2008


"Janice Caron" wrote
> On 1/31/08, Sergey Gromov <snake.scaly at gmail.com> wrote:
>> Maybe a contract should be added for standard library that if a function
>> returns a mutable array, it guarantees that this array can be modified
>> without side effects and therefore can be safely assumed unique.
>
> One problem area where this sort of thing arises is concatenation. If
> you concatenate char arrays, then /regardless/ of the constancy of the
> inputs, the result is guaranteed to be unique (because, by
> specification, concatenation always makes a copy). If we had a
> "unique" type-constructor, one could make the result type unique(T)[].
> But we don't, so D makes the (arbitrary) choice of invariant(T)[].
> Also, it is currently a syntax error to concatenate a char[] with an
> invariant(char)[], even though both will implicitly cast to
> const(char)[].

I actually filed an enhancement request for that.

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

-Steve 





More information about the Digitalmars-d mailing list