const

Walter Bright newshound1 at digitalmars.com
Sat Mar 29 00:05:31 PDT 2008


Janice Caron wrote:
> That's true, but there's a new idea on the block now. A few posts up,
> I suggested that a declaration like
> 
>     const int x = 5;
> 
> should be interpretted by the compiler as if the statement had been
> 
>     invariant int x = 5;
> 
> (Actually, I used the nonclamenture in/const, instead of
> const/invariant, but the meaning doesn't change with the words).
> 
> Essentially, I propose the rule that if any variable is declared to be
> a fully const POD type, then it should be magically retyped to instead
> become fully invariant. Thus, typeof(x) would be invariant(int),
> typeof(&x) would be invariant(int)*, and so on. Hopefully, you can see
> that deconstructing and reconstructing would now still work perfectly.

Yeah, but I can see the bug report now: "dammit, I typed it as const, 
why is it coming out as invariant?"



More information about the Digitalmars-d mailing list