[Issue 1654] Array concatenation should result in mutable or invariant depending on usage

d-bugmail at puremagic.com d-bugmail at puremagic.com
Wed Mar 26 13:05:45 PDT 2008


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


htvennik at zonnet.nl changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |htvennik at zonnet.nl




------- Comment #9 from htvennik at zonnet.nl  2008-03-26 15:05 -------
I read all comments on this enhancement request yesterday, and now I was
thinking about it again and I suddenly realized that the solution is very
simple in fact. D should be extended with a new implicit type qualifier
'unique'. By 'implicit' I mean that such a qualifier should NOT appear anywhere
in the syntax, just like 'mutable' does not appear anywhere in the syntax, but
still exists conceptually. The unique qualifier should be automatically applied
by the compiler to the result type of any expression returning a reference to
newly constructed (or copied) data. Anything of a type qualified as unique
could be implicitly cast to any of mutable, invariant and const.

So if the array concatenation operator is modifier to always return a unique
reference, the following would all be perfectly valid:

char[] mutableString = "foo" ~ "bar";
invariant(char[]) invariantString = "foo" ~ "bar";
invariant(char)[] reassignableInvariantString = "foo" ~ "bar";

Of course a NewExpression would also return a unique reference:

struct S {
    int i;
}

invariant(S) s = new S(4);   // valid


-- 



More information about the Digitalmars-d-bugs mailing list