PhobosWatch: manifest => enum
Janice Caron
caron800 at googlemail.com
Wed Jan 2 11:13:54 PST 2008
On 1/2/08, Russell Lewis <webmaster at villagersonline.com> wrote:
> 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
But typeof(i) /isn't/ int. typeof(i) is const(int). The problem is not
how to make a const copy of a const primitive - it's how to make a
mutable copy of a const primitive.
That's why Walter is introducing manifest constants:
enum int x = 3;
auto i = x; // typeof(i) is int
const j = x; // typeof(i) is const(int)
and why I suggested allowing primitive types to have a .dup property
const int x = 3;
auto i = x.dup; // typeof(i) is int
auto j = x; // typeof(i) is const(int)
> 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*)?
Type deduction only means that
auto x = y;
is equivalent to
typeof(y) x = y;
and if typeof(y) is const(int), well then, so will x be.
More information about the Digitalmars-d
mailing list