Proposal - Revised Syntax for const and final

Bruno Medeiros brunodomedeiros+spam at com.gmail
Mon Sep 10 05:23:51 PDT 2007


Janice Caron wrote:
> OK, I guess you're right about PODs. Let's try again, but more generally:
> 
> Regardless of the type of T:
> 
> final(T) would be a type that was similar to T except that it would be
> const, its members would be mutable, and all of its members' members
> would be mutable, etc..
> 
> const(T) would be a type that was similar to T except that it would be
> const, its members would be const, and all of its members' members
> would be const, etc..
> 
> const*(T) would be a type that was similar to T except that it would
> be mutable, its members would be const, and all of its members'
> members would be const, etc..
> 
> const**(T)  would be a type that was similar to T except that it would
> be mutable, and its members would be mutable, but its members' members
> would be const, etc..
> 
> Now, if some of those possibilities turn out to be nonsense (e.g
> final(int), then we can always make those possibilities compile-time
> errors.
> 
> But it would be consistent, logical, and a boon to generic programming.
> No?

I also agree that current const/invariant semantics are overly strange 
and inconsistent.

Dropping that idea that PODs and classes should work the same (with 
regards to const semantics), I agree your proposal would be more 
consistent and logical, but it still strikes me as too much complicated.

Why the need for const**(T) ? You said:
"Walter wants to make it possible to to specify that the immediate
members of a struct, but not the struct itself, be const*."
And it would work like this:
"
const**(S) s;
s = S();                /* OK* /
s.x = 1;                /* OK */
s.p = new int[1];       /* OK */
s.p[0] = 1;             /* Error */
"
but now considering the struct the same as it's members, that would be 
what const*() does, .

And would we also need const(T)?, given that const(T) is pretty much the 
same as: final const*(T). It would only be syntactic sugar.

-- 
Bruno Medeiros - MSc in CS/E student
http://www.prowiki.org/wiki4d/wiki.cgi?BrunoMedeiros#D



More information about the Digitalmars-d mailing list