PhobosWatch: manifest => enum

Russell Lewis webmaster at villagersonline.com
Wed Jan 2 10:54:08 PST 2008


Walter Bright wrote:
> Jérôme M. Berger wrote:
>> Walter Bright wrote:
>>> Yes, that could be done, but we're still stymied by the problem that we
>>> are unable to declare a constant of type 'int', only 'const(int)'.
>>
>>     I don't see any situation in which we would need a constant of type
>> "int" instead of "const (int)" or "invariant (int)". After all, if
>> it is a *constant*, it should be either "const" or "invariant", no?
> 
> Consider the following:
> 
>     const int X = 3;
>     auto i = X;
>     i = 4;        // error, i is const
> 
> Essentially, it would make type inference far less useful.

I'll ignore for the moment the (very tricky) problem of assigning copies 
of const structs.  Just for basic types, we could easily solve this by 
requiring the syntax "const auto" when we wanted a constant:

     const int X = 3;
           auto i = X;
     const auto j = X;
     i = 4; // legal, typeof(i) is int
     j = 4; // error, j is const

Doesn't it make sense that type deduction (which deals with how the 
variable was declared in the *past*) should be orthogonal from constness 
(which deals with how the variable will be used in the *future*)?



More information about the Digitalmars-d mailing list