Inability to dup/~ for const arrays of class objects

Steven Schveighoffer schveiguy at yahoo.com
Tue May 28 18:33:40 PDT 2013


On Tue, 28 May 2013 21:19:49 -0400, Ali Çehreli <acehreli at yahoo.com> wrote:

>      // C is a class
>      const(C) c = new const(C);
>
>      // c promises that it won't mutate the object.
>      // Why can't it promise to not mutate another object?
>
>      c = new const(C);  // <-- compilation error
>
> I don't see the rationale for disallowing the last line. I think it  
> should work without any syntax change. Merely the class handle is being  
> changed.

The issue is that you cannot separate out the reference from the  
referred-to data, and apply const only to the tail.

It's a syntax issue, not a semantic issue.  It should be allowed, but we  
lack the syntax to specify it.  You can only apply const to both the  
reference and the data.

-Steve


More information about the Digitalmars-d mailing list