PhobosWatch: manifest => enum

Walter Bright newshound1 at digitalmars.com
Sat Dec 29 15:35:55 PST 2007


Bill Baxter wrote:
> 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.
> 
> Huh?  So the fix is to make constants not const?

We don't have to worry about rvalue literals not being const, because:

	2 = 3;

is illegal anyway. But we do need to be concerned about its type, 
because of type inference.

> Seems like the problem 
> lies either in auto or in the expectation that const will not be 
> transferred using auto.  I would actually expect there to be an 
> unconst!(X) template required in there or something if it's going to 
> strip off const.

Would you really prefer to do:

	auto i = Unconst!(X);

? If const were not transferred with auto, then we run smack into the 
tail const problem again.



More information about the Digitalmars-d mailing list