any news on const/invariant?

Regan Heath regan at netmail.co.nz
Thu Nov 29 07:17:43 PST 2007


Janice Caron wrote:
<snip>
> So why not let "const" do double-duty?
> 
> That is, we keep
> (*) const as a storage-class
> (*) const as a type-constructor
> (*) invariant as a type-constructor
> 
> and we lose
> (*) invariant as a storage class
> 
> with the caveat that when const-as-storage-class is applied to types
> which require storage, it actually means invariant (but when applied
> to member functions it retains its existing meaning). If we were to
> adopt this practice then:
> 
>      const x = 3;
>      auto p = &x;
> 
> would result in x having type invariant(int), and p having type
> invariant(int)*. Since invariant can implicitly cast to const, this is
> guaranteed not to break anything.

I think I'd rather loose:
(*) const as a storage-class

and make the separation between const and invariant more pronounced.

There would be no need for the caveat above, however:

const x = 5;

would become illegal and this breaks existing valid 1.0 code.

Regan



More information about the Digitalmars-d mailing list