PhobosWatch: manifest => enum
"Jérôme M. Berger"
jeberger at free.fr
Mon Dec 31 02:15:35 PST 2007
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
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.
OTOH, having something that's a constant but has type "int" instead
of "const (int)" or "invariant (int)" could cause problems with
generic programming. For example with something like this:
- -------------------->8====================
static if (is (typeof (x) : int)
x = 42;
else static if ((is (typeof (x) : const (int))
|| (is (typeof (x) : invariant (int)))
processImmutableInts();
else
static assert (0, "Can only handle ints");
====================8<--------------------
If "x" is in fact a manifest constant, this code will think it is
mutable and try to assign to it but the compiler will then refuse
the assignment...
Jerome
- --
+------------------------- Jerome M. BERGER ---------------------+
| mailto:jeberger at free.fr | ICQ: 238062172 |
| http://jeberger.free.fr/ | Jabber: jeberger at jabber.fr |
+---------------------------------+------------------------------+
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.7 (GNU/Linux)
iD8DBQFHeMFHd0kWM4JG3k8RAj9IAKC+m/8C7+QjF3Kza567mGnaGCC15ACfRp4q
1TCS8yIcZuMG9nBgNfnIDaw=
=wZ6N
-----END PGP SIGNATURE-----
More information about the Digitalmars-d
mailing list