PhobosWatch: manifest => enum
Walter Bright
newshound1 at digitalmars.com
Sat Dec 29 17:23:09 PST 2007
Derek Parnell wrote:
> On Sat, 29 Dec 2007 14:43:28 -0800, 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 think I'm confused here. Are you saying Walter, that in this example, 'i'
> would NOT be const?
No, I'm saying it would be const(int), which is why we need a way to
type a constant as just plain int.
> My simple reasoning goes like this ...
>
> const int X = 3;
>
> declares that X is a 'const int' data type.
>
> auto i = X;
>
> declares that 'i' automatically takes on the data type of 'X', thus 'i' is
> also a 'const int' and its initial (and only) value is the same as in 'X'.
>
> i = 4;
>
> should be an error because i is immutable.
Exactly.
More information about the Digitalmars-d
mailing list